unit UHTTP;
interface
uses classes;
TYPE
THttpHead=class
private
fOtherfields : TStrings;
fPostData : String;
fHttpVer : String;
FMethod : String;
FUrl : String;
fAuthPass : String;
fAuthUser : String;
fAuthType : String;
fAuthorization : string;
fContent_Encoding : string;
fContent_Length : string;
fContent_Type : string;
fFrom : string;
fIf_Modified_Since : string;
fReferer : string;
fUser_Agent : string;
fHost : String;
public
Constructor Create;
Destructor Destroy;override;
Procedure Use(S : String);
function GetOtherVal(s : string) : string;
property otherfields : TStrings read FOtherFields;
property Method : String read fMethod;
property Url : String read FUrl;
property HttpVer : String read FHttpVer;
property Auth_Password : String read fAuthPass;
property Auth_Username : String read fAuthUser;
property Auth_Type : String read fAuthType;
property Authorization : String read fAuthorization;
property Content_Encoding : String read fContent_Encoding;
property Content_Length : String read fContent_Length;
property Content_Type : String read fContent_Type;
property From : String read fFrom;
property Host : string read FHost;
property If_Modified_Since : String read fIf_Modified_Since;
property Referer : String read fReferer;
property User_Agent : String read fUser_Agent;
property PostData : string read FPostData;
end;
implementation
{ THttpHead }
Constructor THttpHead.Create;
begin
inherited Create;
fOtherfields:=TStringlist.Create;
fPostData:='';
end;
Procedure THttpHead.Use(S : String);
var
w1, w2 : String;
begin
s:=s+#13#10;
w2:=copy(s, 1, pos(#13#10, s) -1);
delete(s, 1, pos(#13#10, s)+1);
fMethod:=Copy(w2, 1, pos(' ', w2)-1);
delete(w2, 1, pos(' ', w2));
FUrl:=Copy(w2, 1, pos(' HTTP/', w2)-1);
if furl='' then furl:='/';
if pos('/', furl)<>1 then
furl:='/'+furl;
Delete(w2, 1, pos(' HTTP/', w2)+5);
fHttpVer:=w2;
while pos(#13#10, s)>0 do begin
w2:=copy(s, 1, pos(#13#10, s)-1);
if w2='' then break; {end of header is #13#10#13#10}
delete(s, 1, pos(#13#10, s)+1);
w1:=copy(w2, 1, pos(':', w2)-1);
delete(w2, 1, pos(':', w2));
while pos(' ', w2)=1 do
delete(w2,1,1);
Fotherfields.Add(w1+'='+w2);
end;
fAuthorization:=GetOtherVal('Authorization');
fContent_Encoding:=GetOtherVal('Content-Encoding');
fContent_Length:=GetOtherVal('Content-Length');
fContent_Type:=GetOtherVal('Content-Type');
fFrom:=GetOtherVal('From');
fIf_Modified_Since:=GetOtherVal('If-Modified-Since');
fReferer:=GetOtherVal('Referer');
fUser_Agent:=GetOtherVal('User-Agent');
fHost:=GetOtherVal('Host');
fAuthPass:=FAuthorization;
FAuthType:=copy(fAuthPass, 1, pos(' ', fAuthPass)-1);
delete(fAuthPass, 1, pos(' ', fAuthPass));
fAuthPass:=fAuthPass;
fAuthUser:=copy(fAuthPass, 1, pos(':', fAuthPass)-1);
delete(fAuthPass, 1, pos(':', fAuthPass));
end;
Destructor THttpHead.Destroy;
begin
FOtherfields.free;
inherited Destroy;
end;
function THttpHead.GetOtherVal(s : string) : string;
begin
if fOtherfields.IndexOfName(s)<>-1 then
Result:=fOtherFields.Values
else
Result:='';
end;
end.