Browse Source

--- Merging r22819 into '.':
U packages/fcl-web/src/base/fpwebfile.pp
--- Merging r22842 into '.':
U packages/fcl-web/src/base/FCGI-README.txt
--- Merging r23051 into '.':
U packages/fcl-web/src/base/fphttpclient.pp
--- Merging r23052 into '.':
U packages/fcl-web/src/base/README.txt
G packages/fcl-web/src/base/fphttpclient.pp
--- Merging r23053 into '.':
G packages/fcl-web/src/base/fphttpclient.pp

# revisions: 22819,22842,23051,23052,23053
r22819 | michael | 2012-10-22 13:20:52 +0200 (Mon, 22 Oct 2012) | 1 line
Changed paths:
M /trunk/packages/fcl-web/src/base/fpwebfile.pp

* added comment to explain the DefaultFileModuleClass purpose
r22842 | michael | 2012-10-24 09:14:54 +0200 (Wed, 24 Oct 2012) | 1 line
Changed paths:
M /trunk/packages/fcl-web/src/base/FCGI-README.txt

* Added NGINX instructions
r23051 | michael | 2012-11-23 21:00:58 +0100 (Fri, 23 Nov 2012) | 1 line
Changed paths:
M /trunk/packages/fcl-web/src/base/fphttpclient.pp

* Fix (adapted) from bug #23372
r23052 | michael | 2012-11-23 23:13:35 +0100 (Fri, 23 Nov 2012) | 1 line
Changed paths:
M /trunk/packages/fcl-web/src/base/README.txt
M /trunk/packages/fcl-web/src/base/fphttpclient.pp

* Added some convenience methods
r23053 | michael | 2012-11-23 23:25:55 +0100 (Fri, 23 Nov 2012) | 1 line
Changed paths:
M /trunk/packages/fcl-web/src/base/fphttpclient.pp

* Use actual class instead of hard-coded base class in class methods

git-svn-id: branches/fixes_2_6@23910 -

marco 12 years ago
parent
commit
3875a2ccda

+ 60 - 0
packages/fcl-web/src/base/FCGI-README.txt

@@ -45,6 +45,8 @@ latter case.
 2. mod_fastcgi from fastcgi.com
 2.1 on Windows
 2.1 on Linux
+3. NGINX configuration
+
 ===============================================================================
 
 1. mod_fcgid from Apache:
@@ -400,3 +402,61 @@ http://127.0.0.1/myfcgi/webmodule1/func1call
 If there is any problem, you can try and check the Apache error.log for clues.
 
 ===============================================================================
+
+3. NGINX Configuration
+
+Full configuraion of FastCGI is discussed at:
+
+http://wiki.nginx.org/HttpFastcgiModule
+
+NGINX does not support managing the FastCGI process. The FastCGI process must be
+started outside of the NGINX engine, much like the FastCgiExternalServer
+mode of Apache. NGINX will just forward the requests to whatever port the
+FastCGI process is running on. Note that the fastcgi process does not need
+to be running on the same machine as the NGINX process.
+
+This means that in the FastCGI program, you must set the port on which the 
+FastCGI process is listening:
+
+Example:
+<...snip...>
+  Application.Initialize;
+  Application.Port:=1234;//Port the FCGI application is listening on 
+  Application.Run;
+<...snip...>
+
+And the FastCGI process must be started somehow separately. 
+On windows, a windows service application is most suitable.
+On Unices, a simple process can be put in the system startup scripts.
+
+Then, NGINX must be told to forward all requests to this address.
+
+The following is a sample of a NGINX configuration which sends all requests
+to a FastCGI process, listening on port 1234 on the same machine:
+
+{
+  include /etc/nginx/fastcgi_params;
+
+  location / { 
+     fastcgi_pass 127.0.0.1:1234
+     fastcgi_split_path_info ^((?U).+www.mysite.com)(/?.+)$; 
+     fastcgi_param  PATH_INFO          $fastcgi_path_info; 
+     fastcgi_param  PATH_TRANSLATED    $document_root$fastcgi_path_info; 
+     fastcgi_param  SCRIPT_FILENAME    $document_root$fastcgi_script_name; 
+  } 
+}
+
+The "fastcgi_split_path_info" and fastcgi_param directives are needed, 
+so that the FCL-Web environment gets enough information to act on the
+request. (PATH_INFO and SCRIPT_FILENAME are needed to work correctly)
+
+This is another example:
+
+location ~ /helloworld/.*) {
+  fastcgi_pass    127.0.0.1:1234
+  fastcgi_split_path_info ^((?U)./helloworld)(/?.+)$; 
+  fastcgi_param   PATH_INFO   $path_info;
+  fastcgi_param   SCRIPT_NAME "/helloworld";
+}
+
+All urls below 'helloworld' will be passed on to the FastCGI process.

+ 3 - 0
packages/fcl-web/src/base/README.txt

@@ -165,6 +165,9 @@ TFPCustomHTTPClient:
   other HTTP methods as well. It works using the ssockets unit of FPC, so no
   third-party package to handle the socket communication is needed.
 
+  The class contains class methods, which allow to execute get/post methods in a really
+  simple, one-command way.
+
 A demo application for this class exists.
 
 fphttpserver:

+ 207 - 1
packages/fcl-web/src/base/fphttpclient.pp

@@ -90,12 +90,22 @@ Type
     Procedure Get(Const AURL : String; const LocalFileName : String);
     Procedure Get(Const AURL : String; Response : TStrings);
     Function Get(Const AURL : String) : String;
+    // Simple class methods
+    Class Procedure SimpleGet(Const AURL : String; Stream : TStream);
+    Class Procedure SimpleGet(Const AURL : String; const LocalFileName : String);
+    Class Procedure SimpleGet(Const AURL : String; Response : TStrings);
+    Class Function SimpleGet(Const AURL : String) : String;
     // Simple post
     // Post URL, and Requestbody. Return response in Stream, File, TstringList or String;
     procedure Post(const URL: string; const Response: TStream);
     procedure Post(const URL: string; Response : TStrings);
     procedure Post(const URL: string; const LocalFileName: String);
     function Post(const URL: string) : String;
+    // Simple class methods.
+    Class procedure SimplePost(const URL: string; const Response: TStream);
+    Class procedure SimplePost(const URL: string; Response : TStrings);
+    Class procedure SimplePost(const URL: string; const LocalFileName: String);
+    Class function SimplePost(const URL: string) : String;
     // Post Form data (www-urlencoded).
     // Formdata in string (urlencoded) or TStrings (plain text) format.
     // Form data will be inserted in the requestbody.
@@ -106,8 +116,17 @@ Type
     Procedure FormPost(const URL : string; FormData:  TStrings; const Response: TStrings);
     function FormPost(const URL, FormData: string): String;
     function FormPost(const URL: string; FormData : TStrings): String;
+    // Simple form 
+    Class Procedure SimpleFormPost(const URL, FormData: string; const Response: TStream);
+    Class Procedure SimpleFormPost(const URL : string; FormData:  TStrings; const Response: TStream);
+    Class Procedure SimpleFormPost(const URL, FormData: string; const Response: TStrings);
+    Class Procedure SimpleFormPost(const URL : string; FormData:  TStrings; const Response: TStrings);
+    Class function SimpleFormPost(const URL, FormData: string): String;
+    Class function SimpleFormPost(const URL: string; FormData : TStrings): String;
     // Post a file
     Procedure FileFormPost(const AURL, AFieldName, AFileName: string; const Response: TStream);
+    // Simple form of Posting a file
+    Class Procedure SimpleFileFormPost(const AURL, AFieldName, AFileName: string; const Response: TStream);
   Protected
     // Before request properties.
     // Additional headers for request. Host; and Authentication are automatically added.
@@ -289,7 +308,9 @@ Var
 
 begin
   D:=URI.Path;
-  If (D[1]<>'/') then
+  If Length(D) = 0 then
+    D := '/'
+  else  If (D[1]<>'/') then
     D:='/'+D;
   If (D[Length(D)]<>'/') then
     D:=D+'/';
@@ -810,16 +831,67 @@ begin
   end;
 end;
 
+
+Class Procedure TFPCustomHTTPClient.SimpleGet(Const AURL : String; Stream : TStream);
+
+begin
+  With Self.Create(nil) do
+    try
+      Get(AURL,Stream);
+    finally
+      Free;
+    end;
+end;
+
+
+Class Procedure TFPCustomHTTPClient.SimpleGet(Const AURL : String; const LocalFileName : String);
+
+begin
+  With Self.Create(nil) do
+    try
+      Get(AURL,LocalFileName);
+    finally
+      Free;
+    end;
+end;
+
+
+Class Procedure TFPCustomHTTPClient.SimpleGet(Const AURL : String; Response : TStrings);
+
+begin
+  With Self.Create(nil) do
+    try
+      Get(AURL,Response);
+    finally
+      Free;
+    end;
+end;
+
+
+Class Function TFPCustomHTTPClient.SimpleGet(Const AURL : String) : String;
+ 
+begin
+  With Self.Create(nil) do
+    try
+      Result:=Get(AURL);
+    finally
+      Free;
+    end;
+end;
+
+
 procedure TFPCustomHTTPClient.Post(const URL: string; const Response: TStream);
 begin
   DoMethod('POST',URL,Response,[]);
 end;
 
+
 procedure TFPCustomHTTPClient.Post(const URL: string; Response: TStrings);
 begin
   Response.Text:=Post(URL);
 end;
 
+
 procedure TFPCustomHTTPClient.Post(const URL: string;
   const LocalFileName: String);
 
@@ -835,6 +907,7 @@ begin
   end;
 end;
 
+
 function TFPCustomHTTPClient.Post(const URL: string): String;
 Var
   SS : TStringStream;
@@ -848,6 +921,56 @@ begin
   end;
 end;
 
+
+Class procedure TFPCustomHTTPClient.SimplePost(const URL: string; const Response: TStream);
+
+begin
+  With Self.Create(nil) do
+    try
+      Post(URL,Response);
+    finally
+      Free;
+    end;
+end;
+
+
+Class procedure TFPCustomHTTPClient.SimplePost(const URL: string; Response : TStrings);
+
+begin
+  With Self.Create(nil) do
+    try
+      Post(URL,Response);
+    finally
+      Free;
+    end;
+end;
+
+
+Class procedure TFPCustomHTTPClient.SimplePost(const URL: string; const LocalFileName: String);
+
+begin
+  With Self.Create(nil) do
+    try
+      Post(URL,LocalFileName);
+    finally
+      Free;
+    end;
+end;
+
+
+Class function TFPCustomHTTPClient.SimplePost(const URL: string) : String;
+
+begin
+  With Self.Create(nil) do
+    try
+      Result:=Post(URL);
+    finally
+      Free;
+    end;
+end;
+
+
+
 procedure TFPCustomHTTPClient.FormPost(const URL, FormData: string;
   const Response: TStream);
 
@@ -920,6 +1043,76 @@ begin
   end;
 end;
 
+
+Class Procedure TFPCustomHTTPClient.SimpleFormPost(const URL, FormData: string; const Response: TStream);
+
+begin
+  With Self.Create(nil) do
+    try
+      FormPost(URL,FormData,Response);
+    Finally
+      Free;
+    end;
+end;
+
+
+Class Procedure TFPCustomHTTPClient.SimpleFormPost(const URL : string; FormData:  TStrings; const Response: TStream);
+
+begin
+  With Self.Create(nil) do
+    try
+      FormPost(URL,FormData,Response);
+    Finally
+      Free;
+    end;
+end;
+
+
+Class Procedure TFPCustomHTTPClient.SimpleFormPost(const URL, FormData: string; const Response: TStrings);
+
+begin
+  With Self.Create(nil) do
+    try
+      FormPost(URL,FormData,Response);
+    Finally
+      Free;
+    end;
+end;
+
+Class Procedure TFPCustomHTTPClient.SimpleFormPost(const URL : string; FormData:  TStrings; const Response: TStrings);
+
+begin
+  With Self.Create(nil) do
+    try
+      FormPost(URL,FormData,Response);
+    Finally
+      Free;
+    end;
+end;
+
+Class function TFPCustomHTTPClient.SimpleFormPost(const URL, FormData: string): String;
+
+begin
+  With Self.Create(nil) do
+    try
+      Result:=FormPost(URL,FormData);
+    Finally
+      Free;
+    end;
+end;
+
+Class function TFPCustomHTTPClient.SimpleFormPost(const URL: string; FormData : TStrings): String;
+
+begin
+  With Self.Create(nil) do
+    try
+      Result:=FormPost(URL,FormData);
+    Finally
+      Free;
+    end;
+end;
+
+
 procedure TFPCustomHTTPClient.FileFormPost(const AURL, AFieldName, AFileName: string; const Response: TStream);
 
 Var
@@ -952,5 +1145,18 @@ begin
   end;
 end;
 
+
+Class Procedure TFPCustomHTTPClient.SimpleFileFormPost(const AURL, AFieldName, AFileName: string; const Response: TStream);
+
+begin
+  With Self.Create(nil) do
+    try
+      FileFormPost(AURL,AFieldName,AFileName,Response);
+    Finally
+      Free;
+    end;
+end;
+
+
 end.
 

+ 1 - 0
packages/fcl-web/src/base/fpwebfile.pp

@@ -24,6 +24,7 @@ Type
 
 Var
   // Set this if you want a descendent class to serve the files.
+  // You can use this to customize the behaviour in the descendent, for instance if you have multiple virtual hosts.
   DefaultFileModuleClass : TFPCustomFileModuleClass = TFPCustomFileModule;
   // Setting this will load mime types from that file.
   MimeTypesFile : string;