Browse Source

* Fix bug ID #26462, additionally rework variables to match new interface

git-svn-id: trunk@30650 -
michael 10 years ago
parent
commit
1691ec4481
1 changed files with 20 additions and 49 deletions
  1. 20 49
      packages/fcl-web/src/base/fphttpserver.pp

+ 20 - 49
packages/fcl-web/src/base/fphttpserver.pp

@@ -36,12 +36,7 @@ Type
   TFPHTTPConnectionRequest = Class(TRequest)
   TFPHTTPConnectionRequest = Class(TRequest)
   private
   private
     FConnection: TFPHTTPConnection;
     FConnection: TFPHTTPConnection;
-    FRemoteAddress: String;
-    FServerPort: String;
-    FQueryString : String;
   protected
   protected
-    function GetFieldValue(Index: Integer): String; override;
-    procedure SetFieldValue(Index: Integer; Value: String);override;
     Procedure InitRequestVars; override;
     Procedure InitRequestVars; override;
   published
   published
     Property Connection : TFPHTTPConnection Read FConnection;
     Property Connection : TFPHTTPConnection Read FConnection;
@@ -261,31 +256,12 @@ begin
   end;
   end;
 end;
 end;
 
 
-procedure TFPHTTPConnectionRequest.InitRequestVars;
-Var
-  P : Integer;
-begin
-  P:=Pos('?',URI);
-  if (P<>0) then
-    FQueryString:=Copy(URI,P+1,Length(URI)-P);
-  inherited InitRequestVars;
-end;
-
-Function SocketAddrToString(ASocketAddr: TSockAddr): String;
-begin
-  if ASocketAddr.sa_family = AF_INET then
-    Result := NetAddrToStr(ASocketAddr.sin_addr)
-  else // no ipv6 support yet
-    Result := '';
-end;
-
 Function GetHostNameByAddress(const AnAddress: String): String;
 Function GetHostNameByAddress(const AnAddress: String): String;
 var
 var
   Resolver: THostResolver;
   Resolver: THostResolver;
 begin
 begin
   Result := '';
   Result := '';
   if AnAddress = '' then exit;
   if AnAddress = '' then exit;
-
   Resolver := THostResolver.Create(nil);
   Resolver := THostResolver.Create(nil);
   try
   try
     if Resolver.AddressLookup(AnAddress) then
     if Resolver.AddressLookup(AnAddress) then
@@ -295,36 +271,28 @@ begin
   end;
   end;
 end;
 end;
 
 
-
-Procedure TFPHTTPConnectionRequest.SetFieldValue(Index : Integer; Value : String);
-
+procedure TFPHTTPConnectionRequest.InitRequestVars;
+Var
+  P : Integer;
 begin
 begin
-  case Index of
-    27 : FRemoteAddress := Value;
-    30 : FServerPort := Value;
-    33 : FQueryString:=Value
-  else
-    Inherited SetFieldValue(Index,Value);
-  end;  
+  P:=Pos('?',URI);
+  if (P<>0) then
+    SetHTTPVariable(hvQuery,Copy(URI,P+1,Length(URI)-P));
+  if Assigned(FConnection) and FConnection.LookupHostNames then
+    SetHTTPVariable(hvRemoteHost,GetHostNameByAddress(RemoteAddress));
+  inherited InitRequestVars;
 end;
 end;
 
 
-Function TFPHTTPConnectionRequest.GetFieldValue(Index : Integer) : String;
-
+Function SocketAddrToString(ASocketAddr: TSockAddr): String;
 begin
 begin
-  case Index of
-    27 : Result := FRemoteAddress;
-    28 : // Remote server name
-         if Assigned(FConnection) and FConnection.LookupHostNames then
-           Result := GetHostNameByAddress(FRemoteAddress) 
-         else
-           Result:='';  
-    30 : Result := FServerPort;
-    33 : Result:=FQueryString
-  else
-    Result:=Inherited GetFieldValue(Index);
-  end; 
+  if ASocketAddr.sa_family = AF_INET then
+    Result := NetAddrToStr(ASocketAddr.sin_addr)
+  else // no ipv6 support yet
+    Result := '';
 end;
 end;
 
 
+
+
 procedure TFPHTTPConnectionResponse.DoSendHeaders(Headers: TStrings);
 procedure TFPHTTPConnectionResponse.DoSendHeaders(Headers: TStrings);
 
 
 Var
 Var
@@ -476,7 +444,10 @@ Var
 begin
 begin
   Request.Method:=GetNextWord(AStartLine);
   Request.Method:=GetNextWord(AStartLine);
   Request.URL:=GetNextWord(AStartLine);
   Request.URL:=GetNextWord(AStartLine);
-  Request.PathInfo:=Request.URL;
+  S:=Request.URL;
+  If (S<>'') and (S[1]='/') then
+    Delete(S,1,1);
+  Request.PathInfo:=S;
   S:=GetNextWord(AStartLine);
   S:=GetNextWord(AStartLine);
   If (Pos('HTTP/',S)<>1) then
   If (Pos('HTTP/',S)<>1) then
     Raise EHTTPServer.CreateHelp(SErrMissingProtocol,400);
     Raise EHTTPServer.CreateHelp(SErrMissingProtocol,400);