Unit HttpProt

* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * Author: François PIETTE Email: francois.piette@ping.be http://www.rtfm.be/fpiette francois.piette@rtfm.be Creation: November 23, 1997 Version: 1.10 Description: THttpCli is an implementation for the HTTP protocol RFC 1945 (V1.0), RFC 2068 (V1.1) Support: There is a mailing list for support. See web site for subscription http://www.rtfm.be/fpiette/supportuk.htm Credit: This component is based on a freeware from by Andreas Hoerstemeier and used with his permission. andy@hoerstemeier.de http://www.westend.de/~hoerstemeier Legal issues: Copyright (C) 1997 by François PIETTE 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. Updates: 11/29/97 RcvdStream and SendStream properties moved to public section 11/30/97 Document name bug corrected 12/02/97 Removed bug occuring with terminating slash in docname 12/03/97 Added properties RcvdCount and SentCount to easily add a progress bar feature (On receive, the ContentLength is initialized with the value from the header. Update the progress bar in the OnDocData event, or the OnSendData event). Added the OnSendBegin, OnSendData and OnSendEnd events. 12/07/97 Corrected Head function to work as expected. Thanks to R. Barry Jones . 30/12/97 V0.97 Added a Cookie property to send cookies 11/01/98 V0.98 Added WSocket read-only property which enable to access the socket component used internally. For example to close it to abort a connection. 13/01/98 V0.99 Added MultiThreaaded property to tell the component that it is working in a thread and should take care of it. 15/01/98 V1.00 Completely revised internal working to make it work properly with winsock 2. The TimeOut property is gone. Changed OnAnswerLine event to OnHeaderData to be more consistent. Replaced AnswserLine property by readonly LastResponse property. Added OnRequestDone event. Added GetAsync, PostAsync, HeadAsync asynchronous, non-blocking methods. Added Abort procedure. 16/01/98 V1.01 Corrected a bug which let some data be lost when receiving (thanks to Fulvio J. Castelli ) Added test for HTTP/1.1 response in header. 31/01/98 V1.02 Added an intermediate message posting for the OnRequestDone event. Thanks to Ed Hochman for his help. Added an intermediate PostMessage to set the component to ready state. 04/02/98 V1.03 Added some code to better handle DocName (truncating at the first question mark). 05/02/98 V1.04 Deferred login after a relocation, using WM_HTTP_LOGIN message. Added workarounf to support faulty webservers which sent only a single LF in header lines. Submitted by Alwin Hoogerdijk 15/03/98 V1.05 Enlarge buffers from 2048 to 8192 bytes (not for D1) 01/04/98 V1.06 Adapted for BCB V3 13/04/98 V1.07 Made RcvdHeader property readonly and cleared the content at the start of a request. Protected Abort method from calling when component is ready. Ignore any exception triggered by CancelDnsLookup in Abort method. 14/04/98 V1.08 Corrected a relocation bug occuring with relative path 26/04/98 V1.09 Added OnLocationChange event 30/04/98 V1.10 Added ProxyUsername and ProxyPassword. Suggested by Myers, Mike . * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

Classes

EHttpException -
THttpCli -

Functions

EncodeLine - * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
EncodeStr - * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
ParseURL - * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *} { Syntax of an URL: protocol://[user[:password]@]server[:port]/path
Posn - * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *} { Find the count'th occurence of the s string in the t string.
Register - * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
RFC1123_Date - * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *} {* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *} { We cannot use Delphi own function because the date must be specified in } { english and Delphi use the current language.

Types

TDocDataEvent
THttpEncoding
THttpRequest
THttpRequestDone
THttpState
TOnCommand

Constants

DefaultProxyPort
HttpCliVersion
httperrAborted
httperrBusy
httperrNoData
httperrNoError
HTTP_RCV_BUF_SIZE
HTTP_SND_BUF_SIZE
WM_HTTP_LOGIN
WM_HTTP_REQUEST_DONE
WM_HTTP_SET_READY

Variables


Functions


function EncodeLine(Encoding : THttpEncoding; SrcData : PChar; Size : Integer):String;

* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

function EncodeStr(Encoding : THttpEncoding; const Value : String) : String;

* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

procedure ParseURL(const URL : String; var Proto, User, Pass, Host, Port, Path : String);

* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *} { Syntax of an URL: protocol://[user[:password]@]server[:port]/path

function Posn(const s, t : String; count : Integer) : Integer;

* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *} { Find the count'th occurence of the s string in the t string. } { If count < 0 then look from the back

procedure Register;

* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

function RFC1123_Date(aDate : TDateTime) : String;

* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *} {* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *} { We cannot use Delphi own function because the date must be specified in } { english and Delphi use the current language.

Types


TDocDataEvent    = procedure (Sender : TObject;
                                  Buffer : Pointer;
                                  Len    : Integer) of object

THttpEncoding    = (encUUEncode, encBase64, encMime);

THttpRequest     = (httpAbort, httpGET, httpPOST, httpHEAD);

THttpRequestDone = procedure (Sender : TObject;
                                  RqType : THttpRequest;
                                  Error  : Word) of object

THttpState       = (httpReady,         httpNotConnected, httpDnsLookup,
                        httpWaitingHeader, httpWaitingBody,  httpAborting);

TOnCommand       = procedure (Sender : TObject;
                                  const S: String) of object

Constants

DefaultProxyPort = '80'

HttpCliVersion = 110

Enable partial boolean evaluation } {$T-} { Untyped pointers } {$IFNDEF VER80} { Not for Delphi 1 } {$J+} { Allow typed constant to be modified } {$ENDIF

httperrAborted = 3

httperrBusy = 1

httperrNoData = 2

httperrNoError = 0

HTTP_RCV_BUF_SIZE = 8192

HTTP_SND_BUF_SIZE = 8192

WM_HTTP_LOGIN = WM_USER + 3

WM_HTTP_REQUEST_DONE = WM_USER + 1

WM_HTTP_SET_READY = WM_USER + 2


Variables