OnHeaderInfo event
|
acHTTP component.
|
type
|
TacHTTPHeaderInfoEvent = 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: TacHTTPHeaderInfo;
|
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 acHTTP passes to the OnHeaderInfo event handler following parameters:
|
Parameters | Meaning
|
ErrorCode | the status code of HTTP request (see the list of possible status codes);
|
RawHeadersCRLF | contains ALL the headers reseived from the HTTP server in response to request, as plain text string, separated by CRLF characters (0D0A);
|
ContentType | contains 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;
|
ContentLanguage | identifies 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;
|
ContentEncoding | identifies the encoding method of requested document;
|
ContentLength | determinates 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 (in Perl or PHP);
|
Location | determines 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);
|
Date | shows the date and time at which the HTTP response was originated;
|
LastModified | the 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;
|
Expires | the 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;
|
ETag | ETag, 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;
|
ContinueDownload | used to interrupt the download process. If you don't want to continue download the requested file set it to False.
|
All date/time values that passed to the OnHeaderInfo even handler, is already converted from the server's time to local time, taking in account the time zone and daylight bias. (The acHTTP uses InternetTimeToDateTime function to convert the string representation of date/time to TDateTime value.) To get unmodified string parameters parse the raw headers provided by RawHeadersCRLF parameter.
|
|
This event does not occur if you downloading data from local file (use "file://" prefix in the URL).
|
|
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.
|
OnDone, OnDoneInterrupted, OnHTTPError and OnAnyError events;
|
Abort method;
|
HTTP status codes.
|