?? alhttpcommon.pas
字號:
{*************************************************************
Author: St閜hane Vander Clock (SVanderClock@Arkadia.com)
www: http://www.arkadia.com
EMail: SVanderClock@Arkadia.com
product: Alcinoe Common http function
Version: 3.06
Description: common http function that can be use by HTTP Component
Legal issues: Copyright (C) 1999-2005 by Arkadia Software Engineering
This software is provided 'as-is', without any express
or implied warranty. In no event will the author be
held liable for any damages arising from the use of
this software.
Permission is granted to anyone to use this software
for any purpose, including commercial applications,
and to alter it and redistribute it freely, subject
to the following restrictions:
1. The origin of this software must not be
misrepresented, you must not claim that you wrote
the original software. If you use this software in
a product, an acknowledgment in the product
documentation would be appreciated but is not
required.
2. Altered source versions must be plainly marked as
such, and must not be misrepresented as being the
original software.
3. This notice may not be removed or altered from any
source distribution.
4. You must register this software by sending a picture
postcard to the author. Use a nice stamp and mention
your name, street address, EMail address and any
comment you like to say.
Know bug :
History : 04/10/2005: * Move ALTryGMTHeaderHttpStrToDateTime to
ALTryGMTRFC822StrToGmtDateTime in AlFcnRFC
* Move ALGMTHeaderHttpStrToDateTime to
ALGMTRFC822StrToGmtDateTime in AlFcnRFC
* Move ALGetDefaultFileExtFromHTTPMIMEContentType to
ALGetDefaultFileExtFromMIMEContentType in AlFcnMime
* Move ALGetDefaultHTTPMIMEContentTypeFromExt to
ALGetDefaultMIMEContentTypeFromExt in alFcnMime
04/10/2005: * add some new procedures
* Update TALHTTPRequestCookie and TALHTTPRequestCookieCollection
and TALHTTPRequestHeader in the way they can be use in
the object inspector
Link : http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html
http://wp.netscape.com/newsref/std/cookie_spec.html
Please send all your feedback to SVanderClock@Arkadia.com
**************************************************************}
unit ALHttpCommon;
interface
uses Windows,
Classes,
sysutils,
Wininet;
Type
{-- onchange Event that specify the property index that is just changed --}
TALHTTPPropertyChangeEvent = procedure(sender: Tobject; Const PropertyIndex: Integer) of object;
{--protocol version--}
TALHTTPProtocolVersion = (
HTTPpv_1_0,
HTTPpv_1_1
);
{--Request method--}
TALHTTPRequestMethod = (
HTTPrm_Get,
HTTPrm_Post
);
{--TALHTTPCookie--}
TALHTTPRequestCookie = class(TCollectionItem)
private
FName: string;
FValue: string;
FPath: string;
FDomain: string;
FExpires: TDateTime;
FSecure: Boolean;
protected
function GetHeaderValue: string;
procedure SetHeaderValue(Const aValue: string);
public
constructor Create(Collection: TCollection); override;
procedure AssignTo(Dest: TPersistent); override;
property HeaderValue: string read GetHeaderValue write SetHeaderValue;
Published
property Name: string read FName write FName;
property Value: string read FValue write FValue;
property Domain: string read FDomain write FDomain;
property Path: string read FPath write FPath;
property Expires: TDateTime read FExpires write FExpires;
property Secure: Boolean read FSecure write FSecure Default False;
end;
{--TALCookieCollection--}
TALHTTPRequestCookieCollection = class(TOwnedCollection)
private
protected
function GetCookie(Index: Integer): TALHTTPRequestCookie;
procedure SetCookie(Index: Integer; Cookie: TALHTTPRequestCookie);
public
function Add: TALHTTPRequestCookie;
property Items[Index: Integer]: TALHTTPRequestCookie read GetCookie write SetCookie; default;
end;
{--Request header--}
TALHTTPRequestHeader = Class(Tcomponent)
Private
fAccept: String;
fAcceptCharSet: String;
fAcceptEncoding: String;
fAcceptLanguage: String;
fAllow: String;
fAuthorization: String;
fCacheControl: String;
fConnection: string;
fContentEncoding: string;
fContentLanguage: string;
fContentLength: string;
fContentLocation: string;
fContentMD5: string;
fContentRange: string;
fContentType: string;
fDate: string;
fExpect: string;
fExpires: string;
fFrom: String;
fHost: String;
fIfMatch: string;
fIfModifiedSince: string;
fIfNoneMatch: string;
fIfRange: string;
fIfUnmodifiedSince: string;
fLastModified: string;
fMaxForwards: string;
fPragma: string;
fProxyAuthorization: string;
fRange: string;
fReferer: String;
fTE: string;
fTrailer: String;
fTransferEncoding: String;
fUpgrade: String;
fUserAgent: String;
fVia: String;
fWarning: String;
FCustomHeaders: Tstrings;
FCookies: TALHTTPRequestCookieCollection;
FOnChange: TALHTTPPropertyChangeEvent;
Procedure DoChange(propertyIndex: Integer);
procedure SetHeaderValueByPropertyIndex(const Index: Integer; const Value: string);
Function GetRawHeaderText: String;
procedure SetRawHeaderText(const aRawHeaderText: string);
procedure SetCookies(const Value: TALHTTPRequestCookieCollection);
procedure SetCustomHeaders(const Value: Tstrings);
protected
procedure AssignTo(Dest: TPersistent); override;
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
procedure Clear;
Property RawHeaderText: String read GetRawHeaderText write SetRawHeaderText;
Published
property Accept: String index 0 read FAccept write SetHeaderValueByPropertyIndex; {Accept: audio/*; q=0.2, audio/basic}
property AcceptCharSet: String index 1 read FAcceptCharSet write SetHeaderValueByPropertyIndex; {Accept-Charset: iso-8859-5, unicode-1-1;q=0.8}
property AcceptEncoding: String index 2 read FAcceptEncoding write SetHeaderValueByPropertyIndex; {Accept-Encoding: gzip;q=1.0, identity; q=0.5, *;q=0}
property AcceptLanguage: String index 3 read FAcceptLanguage write SetHeaderValueByPropertyIndex; {Accept-Language: da, en-gb;q=0.8, en;q=0.7}
property Allow: String index 4 read FAllow write SetHeaderValueByPropertyIndex; {Allow: GET, HEAD, PUT}
property Authorization: String index 5 read FAuthorization write SetHeaderValueByPropertyIndex; {Authorization: BASIC d2VibWFzdGVyOnpycW1hNHY=}
property CacheControl: String index 6 read FCacheControl write SetHeaderValueByPropertyIndex; {Cache-Control: no-cache}
property Connection: string index 7 read FConnection write SetHeaderValueByPropertyIndex; {Connection: close}
property ContentEncoding: string index 8 read FContentEncoding write SetHeaderValueByPropertyIndex; {Content-Encoding: gzip}
property ContentLanguage: string index 9 read FContentLanguage write SetHeaderValueByPropertyIndex; {Content-Language: mi, en}
property ContentLength: string index 10 read FContentLength write SetHeaderValueByPropertyIndex; {Content-Length: 3495}
property ContentLocation: string index 11 read FContentLocation write SetHeaderValueByPropertyIndex; {Content-Location: http://localhost/page.asp}
property ContentMD5: string index 12 read FContentMD5 write SetHeaderValueByPropertyIndex; {Content-MD5: [md5-digest]}
property ContentRange: string index 13 read FContentRange write SetHeaderValueByPropertyIndex; {Content-Range: bytes 2543-4532/7898}
property ContentType: string index 14 read FContentType write SetHeaderValueByPropertyIndex; {Content-Type: text/html; charset=ISO-8859-4}
property Date: string index 15 read FDate write SetHeaderValueByPropertyIndex; {Date: Tue, 15 Nov 1994 08:12:31 GMT}
property Expect: string index 16 read fExpect write SetHeaderValueByPropertyIndex; {Expect: 100-continue}
property Expires: string index 17 read FExpires write SetHeaderValueByPropertyIndex; {Expires: Thu, 01 Dec 1994 16:00:00 GMT}
property From: String index 18 read FFrom write SetHeaderValueByPropertyIndex; {From: webmaster@w3.org}
property Host: String index 19 read FHost write SetHeaderValueByPropertyIndex; {Host: www.w3.org}
property IfMatch: string index 20 read FIfMatch write SetHeaderValueByPropertyIndex; {If-Match: entity_tag001}
property IfModifiedSince: string index 21 read FIfModifiedSince write SetHeaderValueByPropertyIndex; {If-Modified-Since: Sat, 29 Oct 1994 19:43:31 GMT}
property IfNoneMatch: string index 22 read fIfNoneMatch write SetHeaderValueByPropertyIndex; {If-None-Match: entity_tag001}
property IfRange: string index 23 read fIfRange write SetHeaderValueByPropertyIndex; {If-Range: entity_tag001}
property IfUnmodifiedSince: string index 24 read fIfUnmodifiedSince write SetHeaderValueByPropertyIndex; {If-Unmodified-Since: Sat, 29 Oct 1994 19:43:31 GMT}
property LastModified: string index 25 read fLastModified write SetHeaderValueByPropertyIndex; {Last-Modified: Tue, 15 Nov 1994 12:45:26 GMT}
property MaxForwards: string index 26 read fMaxForwards write SetHeaderValueByPropertyIndex; {Max-Forwards: 3}
property Pragma: string index 27 read FPragma write SetHeaderValueByPropertyIndex; {Pragma: no-cache}
property ProxyAuthorization: string index 28 read FProxyAuthorization write SetHeaderValueByPropertyIndex; {Proxy-Authorization: [credentials]}
property Range: string index 29 read FRange write SetHeaderValueByPropertyIndex; {Range: bytes=100-599}
property Referer: String index 30 read FReferer write SetHeaderValueByPropertyIndex; {Referer: http://www.w3.org/hypertext/DataSources/Overview.html}
property TE: string index 31 read fTE write SetHeaderValueByPropertyIndex; {TE: trailers, deflate;q=0.5}
property Trailer: String index 32 read FTrailer write SetHeaderValueByPropertyIndex; {Trailer: Date}
property TransferEncoding: String index 33 read FTransferEncoding write SetHeaderValueByPropertyIndex; {Transfer-Encoding: chunked}
property Upgrade: String index 34 read FUpgrade write SetHeaderValueByPropertyIndex; {Upgrade: HTTP/2.0, SHTTP/1.3, IRC/6.9, RTA/x11}
property UserAgent: String index 35 read FUserAgent write SetHeaderValueByPropertyIndex; {User-Agent: CERN-LineMode/2.15 libwww/2.17b3}
property Via: String index 36 read FVia write SetHeaderValueByPropertyIndex; {Via: 1.0 ricky, 1.1 mertz, 1.0 lucy}
property Warning: String index 37 read FWarning write SetHeaderValueByPropertyIndex; {Warning: 112 Disconnected Operation}
property CustomHeaders: Tstrings read FCustomHeaders write SetCustomHeaders;
Property Cookies: TALHTTPRequestCookieCollection read FCookies write SetCookies;
property OnChange: TALHTTPPropertyChangeEvent read FOnChange write FOnChange;
end;
{--Response header--}
TALHTTPResponseHeader = Class(TPersistent)
Private
FAcceptRanges: String;
FAge: String;
FAllow: String;
FCacheControl: String;
FConnection: string;
FContentEncoding: string;
FContentLanguage: string;
FContentLength: string;
FContentLocation: string;
FContentMD5: string;
FContentRange: string;
FContentType: string;
FDate: string;
FETag: String;
FExpires: string;
FLastModified: string;
FLocation: String;
FPragma: string;
FProxyAuthenticate: String;
FRetryAfter: String;
FServer: String;
FTrailer: String;
FTransferEncoding: String;
FUpgrade: String;
FVary: String;
FVia: String;
FWarning: String;
FWWWAuthenticate: String;
FRawHeaderText: string;
FCustomHeaders: Tstrings;
FCookies: Tstrings;
FStatusCode: String;
FHttpProtocolVersion: String;
FReasonPhrase: String;
procedure SetRawHeaderText(const aRawHeaderText: string);
Function GetRawHeaderText: String;
protected
procedure AssignTo(Dest: TPersistent); override;
public
constructor Create; virtual;
destructor Destroy; override;
procedure Clear;
property AcceptRanges: String read FAcceptRanges; {Accept-Ranges: bytes}
property Age: String read FAge; {Age: 2147483648(2^31)}
property Allow: String read FAllow; {Allow: GET, HEAD, PUT}
property CacheControl: String read FCacheControl; {Cache-Control: no-cache}
property Connection: string read FConnection; {Connection: close}
property ContentEncoding: string read FContentEncoding; {Content-Encoding: gzip}
property ContentLanguage: string read FContentLanguage; {Content-Language: mi, en}
property ContentLength: string read FContentLength; {Content-Length: 3495}
property ContentLocation: string read FContentLocation; {Content-Location: http://localhost/page.asp}
property ContentMD5: string read FContentMD5; {Content-MD5: [md5-digest]}
property ContentRange: string read FContentRange; {Content-Range: bytes 2543-4532/7898}
property ContentType: string read FContentType; {Content-Type: text/html; charset=ISO-8859-4}
property Date: string read FDate; {Date: Tue, 15 Nov 1994 08:12:31 GMT}
property ETag: String read FETag; {ETag: W/"xyzzy"}
property Expires: string read FExpires; {Expires: Thu, 01 Dec 1994 16:00:00 GMT}
property LastModified: string read FLastModified; {Last-Modified: Tue, 15 Nov 1994 12:45:26 GMT}
property Location: String read FLocation; {Location: http://www.w3.org/pub/WWW/People.html}
property Pragma: string read FPragma; {Pragma: no-cache}
property ProxyAuthenticate: String read FProxyAuthenticate; {Proxy-Authenticate: [challenge]}
property RetryAfter: String read FRetryAfter; {Retry-After: Fri, 31 Dec 1999 23:59:59 GMT}
property Server: String read FServer; {Server: CERN/3.0 libwww/2.17}
property Trailer: String read FTrailer; {Trailer: Date}
property TransferEncoding: String read FTransferEncoding; {Transfer-Encoding: chunked}
property Upgrade: String read FUpgrade; {Upgrade: HTTP/2.0, SHTTP/1.3, IRC/6.9, RTA/x11}
property Vary: String read FVary; {Vary: Date}
property Via: String read FVia; {Via: 1.0 ricky, 1.1 mertz, 1.0 lucy}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -