About the author
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; IdHTTP1.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 begin LHeader := RawHeaders.Names[ I ]; if (LHeader<>'User-Agent') and (LHeader<>'Host') and (LHeader<>'xxx') and (LHeader<>'yyy') then SL.Add(LHeader); end; // Pretend we're some other browser RawHeaders.Values['User-Agent'] := 'custom user-agent'; for LHeader in SL do RawHeaders.Values[LHeader] := ''; finally SL.Free; end; end;
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