Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Delphi w Indy 10: idHTTPRequest POST always is HTTP 1.0, how to make it HTTP 1.1?

Tags:

delphi

indy

We are doing POST requests to a web service.

Works fine.

However, we notice that the requests are always HTTP 1.0, which causes our web server to decline to gzip the responses.

If the requests are HTTP 1.1, then the responses are gzipped.

How do we properly ask Indy 10 to issue HTTP 1.1 POST requests?

Thank you!

like image 644
Jonesome Reinstate Monica Avatar asked Dec 09 '14 21:12

Jonesome Reinstate Monica


1 Answers

Include the hoKeepOrigProtocol option into the HTTPOptions property set (set it to True). Except that keep the ProtocolVersion property set to pv1_1 (which is the default value).

In the TIdCustomHTTP.Post method code there's a comment explaining the current behavior:

Currently when issuing a POST, IdHTTP will automatically set the protocol to version 1.0 independently of the value it had initially. This is because there are some servers that don't respect the RFC to the full extent. In particular, they don't respect sending/not sending the Expect: 100-Continue header. Until we find an optimum solution that does NOT break the RFC, we will restrict POSTS to version 1.0.

A few lines below is the change to the version 1.0 with the following comment:

// If hoKeepOrigProtocol is SET, it is possible to assume that the developer
// is sure in operations of the server
if not (hoKeepOrigProtocol in FOptions) then begin
  if Connected then begin
    Disconnect;
  end;
  FProtocolVersion := pv1_0;
end;

And the above code is skipped (the version is not changed) if you have the hoKeepOrigProtocol option included in the HTTPOptions.

like image 103
TLama Avatar answered Nov 15 '22 08:11

TLama