Recent

Author Topic: lnet HTTP request range  (Read 8929 times)

streeto

  • Newbie
  • Posts: 3
lnet HTTP request range
« on: July 02, 2010, 09:56:25 pm »
Hi. I searched a lot in this forum and have not found a post about this issue.

I am using lnet TLHTTPClientComponent to download a file. In some situations, I need to request only a part of the file. In HTTP this means adding "Range: bytes=start-end" to the header. TLHTTPClient has the properties RangeStart and RangeEnd, which according to the source add the proper header to the connection.

The thing is, this does not work. When these properties are set, I get a OnDisconnect event right after the request. Things work nicely otherwise. Is this the right way to make a ranged request?

Here is what I use to initialize the connection.

Code: [Select]
  Client := TLHTTPClientComponent.Create(nil);
  DecomposeURL(EditUrl.Text, Host, URI, Port);
  Client.Host := Host;
  Client.Port := Port;
  Client.URI := URI;
  Client.Method:= hmGet;
  Client.Timeout := 10000;
  Client.OnDisconnect := @ClientDisconnect;
  Client.OnDoneInput := @ClientDoneInput;
  Client.OnError := @ClientError;
  Client.OnInput := @ClientInput;
  Client.OnProcessHeaders := @ClientProcessHeaders;
  Client.RangeStart := 10;
  Client.RangeEnd := 100;
  Client.SendRequest;

Almindor

  • Sr. Member
  • ****
  • Posts: 412
    • http://www.astarot.tk
Re: lnet HTTP request range
« Reply #1 on: July 03, 2010, 03:24:56 pm »
I must admit this area of lNet is outside of my expertise (http was done by Micha Nelissen [neli]). I'll try to figure out if this is a bug or something is missing on your end.

streeto

  • Newbie
  • Posts: 3
Re: lnet HTTP request range
« Reply #2 on: July 05, 2010, 04:04:47 pm »
Just to add some context, and possibly help with the bug report, I attached a very simple example.

streeto

  • Newbie
  • Posts: 3
Re: lnet HTTP request range
« Reply #3 on: July 09, 2010, 12:04:24 am »
Using Synapse it is possible to request a range of a document. One must work a way around the blocking methods, using threds perhaps. Here is a sample code:

Code: [Select]
  Response := TStringList.Create;
  HTTP := THTTPSend.Create;
  HTTP.RangeStart := 1;
  HTTP.RangeEnd := 300;
  try
    Result := HTTP.HTTPMethod('GET', URL);
    if Result then
      Response.LoadFromStream(HTTP.Document);
  finally
    HTTP.Free;
  end;

 

TinyPortal © 2005-2018