TIdHTTP component changing Request->CustomHeaders [Edit]

Giganews Newsgroups
Subject:TIdHTTP component changing Request->CustomHeaders [Edit]
Posted by: James Nachbar
Date:Tue, 29 Jun 2010

I have some code I have been using to authenticate with Google Calendar in CB2009.  However, on upgrading to CB2010, it no longer works.  I have isolated the problem to the fact that the TIdHTTP component is changing my CustomHeaders.

I send my username and password to Google, and get back an auth string which needs to be sent to Google with subsequent requests.  I have been putting the auth string into the request's CustomHeader, but it gets changed by the TIdHTTP component.

To reproduce this, drop a TIdHTTP on a form, along with a button.  In the button handler:

TStringList* strings = new TStringList();
strings->Add("auth=1234");
IdHTTP1->Request->CustomHeaders->Assign(strings);
String str = IdHTTP1->Request->CustomHeaders->Strings[0];
ShowMessage(str);

The MessageBox will show that str is now "auth: 1234".  That is to say, the equals sign is changed to a colon and a space.  That was not the behavior seen with the TIdHTTP in CB2009, and it causes Google to reject the auth string.  This occurs in spite of the setting of hoForceEncodeParams in HTTPOptions, and is contrary to the docs, which say of CustomHeaders: "*Any values in CustomHeaders are appended to the text without any additional processsing.*"

Any idea why this is happening, and how I can get back the old behavior of not changing my CustomHeaders?

Thanks!

PS:  I found a workaround:  If I set IdHTTP1->Request->CustomHeaders->NameValueSeparator = "=" I apparently keep the equals sign from being changed to a colon and a space.  However, that still does not explain why the substitution is occurring at all, or why the behavior was changed from CB2009, or why the docs say that CustomHeaders are not subject to additional processing.

Edited by: James Nachbar on Jun 29, 2010 6:09 AM to add workaround

Replies