Forum > Networking and Web Programming

lnet HTTP request range


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: ---  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;

--- End code ---

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.

Just to add some context, and possibly help with the bug report, I attached a very simple example.

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: ---  Response := TStringList.Create;
  HTTP := THTTPSend.Create;
  HTTP.RangeStart := 1;
  HTTP.RangeEnd := 300;
    Result := HTTP.HTTPMethod('GET', URL);
    if Result then

--- End code ---


[0] Message Index

Go to full version