While working on a project which uses the TIdHTTP component, I realized I needed to eliminate certain HTTP headers from being sent.
After examining the logic flow in Indy's TIdHTTP component, I realized that all I needed to do to manipulate HTTP headers is to create a TIdHttpRequest descendant, and override the SetHeaders method.
Then, before making a call to any of the TIdHTTP.Get methods, assign an instance of the TIdHttpRequest descendant to the TIdHTTP.Request property, like so:
IdHTTP1.Request.Free;
IdHTTP1
.
Request
Free;
Request := TIdHTTPRequestReplacement
Create(IdHTTP1);
Here's what the SetHeaders method looks like:
procedure
TIdHTTPRequestReplacement
SetHeaders;
var
I:
Integer
;
LHeader:
string
SL: TStringList;
begin
inherited
SL := TStringList
Create;
try
// Clear any headers that is not User-Agent, Host, etc...
for
I :=
0
to
RawHeaders
Count-
1
do
LHeader := RawHeaders
Names[ I ];
if
(LHeader<>
'User-Agent'
)
and
'Host'
'xxx'
'yyy'
then
SL
Add(LHeader);
end
// Pretend we're some other browser
Values[
] :=
'custom user-agent'
LHeader
in
Values[LHeader] :=
''
finally
Learn why the map is cool in Go!
A method to design records so that they're allocated on a specific byte boundary, such as 16 bytes, 512 bytes, 4096 bytes, etc.
Learn the command line used to compile System.pas in Delphi
How to free more space on your home drive by redirecting the location for SDKs in RAD Studio