10

I'm using Delphi XE2 and Indy 10.5.8.0. I have an instance of TIdHttp and I need to add a custom header to the request. The header value has commas in it so it's getting parsed automatically into multiple headers. I don't want it to do that. I need the header value for my custom header to still be one string and not split based on a comma delimiter.

I have tried setting IdHttp1.Request.CustomHeaders.Delimiter := ';' with no success. Is there a way to make sure the header doesn't get split up?

procedure SendRequest;
const HeaderStr = 'URL-Encoded-API-Key VQ0_RV,ntmcOg/G3oA==,2012-06-13 16:25:19';
begin
  IdHttp1.Request.CustomHeaders.AddValue('Authorization', HeaderStr);
  IdHttp1.Get(URL);
end;
Sam M
  • 4,136
  • 4
  • 29
  • 42
  • 1
    IIRC you can do: IdHttp1.Request.CustomHeaders.Value['Authorization'] := HeaderStr; and so on for all "custom headers", don't forget about SSL! –  Jun 13 '12 at 22:40
  • 1
    Whether you use `AddValue()` or `Value[]`, the string ultimately ends up in `TIdHeaderList.FoldAndInsert()`, which is where the string gets parsed, split into pieces, and added to the list. – Remy Lebeau Jun 13 '12 at 22:56

1 Answers1

6

I am not able to reproduce this issue using the latest Indy 10.5.8 SVN snapshot. The string you have shown gets assigned as a single line for me.

With that said, by default the TIdHeaderList.FoldLines property is set to True, and lines get folded on whitespace and comma characters, so that would explain why your string is getting split. Near as I can tell, there have not been any logic changes made to the folding algorithm between your version of Indy and the latest version in SVN.

Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770
  • Setting FoldLines to False did the trick. The Indy documentation in Delphi says FoldLength is what forces the header value to wrap (not whitespace or commas) so I hadn't even bothered with folding. A great undocumented trick, thanks Remy! – Sam M Jun 13 '12 at 23:02
  • The default value of the `TIdHeaderList.FoldLength` property is 78. The length of the final header you are adding is 75, so it should not be getting folded into multiple lines even with the `TIdHeaderList.FoldLines` property set to True. When I shorten the `TIdHeaderList.FoldLength` property to 74 or less, I see your line get folded as expected. So in your case, you could alterantively set the `FoldLength` to a higher value than 75 (if it is not already), or to `MaxInt` to disable folding a different way. – Remy Lebeau Jun 13 '12 at 23:27
  • When a line is being folded, it gets folded at the whitespace/comma character that is closest to the `FoldLength` position of the line. – Remy Lebeau Jun 13 '12 at 23:33
  • "*The default value of the `TIdHeaderList.FoldLength` property is 78*" - FYI, since Sept 2013, Indy now sets the default `FoldLength` to `MaxInt` in `TIdHTTP`, thus effectively disabling folding. – Remy Lebeau Mar 17 '22 at 01:15