0

To send a big file via winHttp Typically we do a loop like the one below (from delphi source code) :

    while LRequest.FSourceStream.Position < LRequest.FSourceStream.Size do
    begin
      ToRead := LRequest.FSourceStream.Size - LRequest.FSourceStream.Position;
      LRequest.FSourceStream.ReadBuffer(Buffer, ToRead);
      // Write data to the server.
      if not WinHttpWriteData(LRequest.FWRequest, Buffer[0], ToRead, @BytesWritten) then
        raise ENetHTTPClientException.CreateResFmt(@SNetHttpClientSendError, [GetLastError, SysErrorMessage(GetLastError, GLib.Handle)]);
    end;

Now the problem is that on the Server, if I don't read the content of the request (just the header) then it's will not stop the previous loop. Is their any way to stop the previous loop when the server don't request to read more byte ?

zeus
  • 12,173
  • 9
  • 63
  • 184
  • 1
    An HTTP message consists of headers *AND* body, even if the body is empty. The server *MUST* read the whole request message, even if it does not use the body content, otherwise it risks corrupting communications with the client, especially if HTTP keep-alives are used. The *ONLY* way the server could stop the client from sending the body is for the server to disconnect the client after the server finishes reading the headers, in which case `WinHttpWriteData()` will fail to write and the loop can exit. – Remy Lebeau Mar 06 '18 at 19:49
  • hmm so we must always send all the data ? even if it's a 10 GB video movie ? – zeus Mar 06 '18 at 19:51
  • HTTP 1.1 has a feature where the client can send an `Expect: 100-continue` request header, and if the server recognizes that header then it will notify the client via an intermediate `100 Continue` reply if it is safe for the client to then send the body. If the server replies with an error, don't send the body. If the server does not reply at all for a given period of time, assume the server does not recognize `Expect` and just send the body to complete the request. – Remy Lebeau Mar 06 '18 at 19:55
  • See [RFC 2616 section 8.2.3](https://tools.ietf.org/html/rfc2616#section-8.2.3) and [RFC 7231 section 5.1.1](https://tools.ietf.org/html/rfc7231#section-5.1.1) for more details. Whether or not you can utilize this feature with WinHTTP, I don't know. – Remy Lebeau Mar 06 '18 at 19:58
  • thanks remy ! anyway i m quite sure nor Indy not TnetHttpclient support such feature :( – zeus Mar 06 '18 at 20:08
  • by the way remy, do you know how from inside an Isapi to cut the connection ? – zeus Mar 06 '18 at 20:14
  • No, `100-continue` is not currently supported by Indy's `TIdHTTP` component (it is by `TIdHTTPServer, though). I don't know about `TNetHttpClient`, but probably not. And I don't know anything about ISAPI or how it works. – Remy Lebeau Mar 06 '18 at 20:29

0 Answers0