0

Please can someone (Remy Lebeau?) clarify the point on header line folding in TidHTTP? My server expects headers to be folded if the line exceeds 998 characters, which one of mine certainly will.

Among many other posts discussing this I saw this one which is a more or less definitive post from a while back where Remy says

by default the TIdHeaderList.FoldLines property is set to True

and

the default value of the TIdHeaderList.FoldLength property is 78

which seem to indicate that I don't need to do anything special to get my headers folded when using TIdHTTP.

However, looking at the source code of TidHTTP I find comments from Remy such as these (in TIdCustomHTTP.Post)

Currently when issuing a POST, IdHTTP will automatically set the protocol to version 1.0 independently of the value it had initially.

and (in TIdHTTPProtocol.BuildAndSendRequest)

TODO: disable header folding for HTTP 1.0 requests

Which appear to indicate that my request is going to be using HTTP 1.0 requests anyway, regardless if I ask for 1.1 or not and that the header lines will not be folded regardless.

My question therefore is simply; when using TidHttp ver 10.5498 do I need the lines

 IdHTTP1.Request.CustomHeaders.FoldLines := true;    
 IdHTTP1.Request.CustomHeaders.FoldLength := 998;  //could be less, but not more

or can I simply accept the defaults and be confident that my headers will be correctly folded?

user2834566
  • 775
  • 9
  • 22

1 Answers1

2

The default FoldLength is 78 chars unless the QuoteType is QuoteHTTP, then the default is MaxInt instead (effectively disabling folding for HTTP headers even if FoldLines is True). So, if you want your HTTP headers folded at 998 chars, you do need to set the FoldLength manually.

Note that while RFC 1945 (for HTTP 1.0) and RFC 2616 (for HTTP 1.1) do allow headers to be folded:

Header fields can be extended over multiple lines by preceding each extra line with at least one SP or HT, though this is not recommended.

<nbsp;>

Header fields can be extended over multiple lines by preceding each extra line with at least one SP or HT.

RFC 7230 (which updates HTTP 1.1) deprecates that practice:

Historically, HTTP header field values could be extended over multiple lines by preceding each extra line with at least one space or horizontal tab (obs-fold). This specification deprecates such line folding except within the message/http media type (Section 8.3.1). A sender MUST NOT generate a message that includes line folding (i.e., that has any field-value that contains a match to the obs-fold rule) unless the message is intended for packaging within the message/http media type.

As for TIdHTTP forcing HTTP 1.0 for POST requests, you can prevent that by enabling the hoKeepOrigProtocol flag in the TIdHTTP.HTTPOptions property.

Community
  • 1
  • 1
Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770
  • Brilliant, thank you for the full explanation. Data comms seems a minefield of subtle nuances, I don't know how you keep up! (Been away, hence late response). Answer accepted – user2834566 Jun 05 '19 at 06:54