http OnHeaderInfo event
Return to Introduction  Previous page  Next page
Applies to
WinHTTP component.  

Declaration
type  
  TWinHTTPHeaderInfoEvent = procedure(Sender: TObject; ErrorCode: Integer;  
    const RawHeadersCRLF, ContentType, ContentLanguage, ContentEncoding: String;  
    ContentLength: Integer; const Location: String;  
    const Date, LastModified, Expires: TDateTime; const ETag: String;  
    var ContinueDownload: Boolean) of object;  
 
property OnHeaderInfo: TWinHTTPHeaderInfo;  

Description
The OnHeaderInfo event returns the headers the response from the HTTP server, before downloading the document content.  
 
You can write this event handler to receive all response headers and to decide whether you want to download the document. If you decided to NOT download it, (for example, if ErrorCode is not 200-OK, and not 206-Partial content) simply set ContinueDownload parameter to False in the event handler.  
 
The WinHTTP passes to the OnHeaderInfo event handler following parameters:  
ParametersMeaning  
ErrorCodethe status code of HTTP request (see the list of possible status codes);  
RawHeadersCRLFcontains ALL the headers reseived from the HTTP server in response to request, as plain text string, separated by CRLF characters (0D0A);  
ContentTypecontains the identifier of MIME-type of requested document. For more information about Internet media types, please read RFC 2045, 2046, 2047, 2048, and 2077. Check out also the Internet media type registry at ftp://ftp.iana.org/in-notes/iana/assignments/media-types;  
ContentLanguageidentifies a language of document content (if provided), or contains empty string if the language is not provided or not applicable for the type requested document;  
ContentEncodingidentifies the encoding method of requested document;  
ContentLengthdeterminates the size of document, if the document is binary file. Unfortunately most servers does not provide the content length for ASCII documents with "text/*" MIME-type, since their content can be generated dynamically by CGI programs;  
Locationdetermines the location from where the content is about to be downloaded (use this parameter to get the actual location of document in case if connection has been redirected by server to another location);  
Dateshows the date and time at which the HTTP response was originated;  
LastModifiedthe date and time at which the server belives the resource was last modified. Note: Servers without a clock assign ETag parameter instead of last modified and expiration time;  
Expiresthe date and time after which the resource should be considered outdated. Note: Servers without a clock assign ETag parameter instead of last modified and expiration time;  
ETagETag, also known as "Expires Tag", or some another additional information from server. This information generated automatically by server without a clock (in this case LastModified and Expires values are not set), or generated dynamically by CGI program (in Perl or PHP) and used to transfer some important information, i.e: whether the document expired etc;  
ContinueDownloadused to interrupt the download process. If you don't want to continue download the requested file — set it to False.  

Notes
iiwarning If you set ContinueDownload parameter to True (imediately terminate the process without downloading of the content of document), neither OnAnyError and OnHTTPError events will not called. The only event which you will received after it — is OnDoneInterrupted. This means that if you plan to handle HTTP errors in OnHTTPError event handler, you must move this code to OnHeaderInfo event handler.  
 
iiwarning This event does not occur if you downloading data from local file (use "file://" prefix in the URL).  

See also
OnDone, OnDoneInterrupted, OnHTTPError and OnAnyError events;  
Abort method;  
HTTP status codes.