[Lazarus] fpWeb & fcgi

Lee Jenkins lee at datatrakpos.com
Sat May 14 19:13:23 CEST 2011


On 5/9/2011 6:48 AM, Joost van der Sluis wrote:
> On Sun, 2011-05-08 at 23:41 -0400, Lee Jenkins wrote:
>> I have a web type project coming up and decided to poke around in the fpWeb
>> stuff.  My, you guys have been busy, I never took a good look around the
>> fpweb/laz web sources till today.  I was thinking of using php with symfony or
>> one of the smaller frameworks, but its a bit overkill for my project.  I'm
>> considering using fpweb/lazarus so I'm writing a small test application.
>>
>> I thought I saw mention of a embedded web server available?  I currently have a
>> pretty simple embedded server using synapse that is a modified version of the
>> demo that comes with the sources.  I was thinking of writing a
>> TCustomWebApplication to use that.  But I did remember somewhere in a recent
>> thread, there was mention of an existing embedded server...?
>
> fppkg update
> fppkg install embweb
> restart Lazarus
> In Lazarus->install packages->  select embweb->  install
>

I tried that with the latest snapshot and it spat out an AV.  I guess the FPC 
2.4.3 doesn't work for that?

The problem is that I'm on Windows and its such a bear to setup Lazarus/FPC to 
compile from sources, at least in my limited experience in doing it.

What I'd really like to do anyway is write a TCustomWebApplication descendant 
for the Synapse server I've been using for a while now.  It also supports HTTPS 
with openssl which is a nice bonus for the application that I have in to write 
since it needs to be stand alone with the possibility of scaling up to use 
apache mod or fastcgi for larger installations.

I've been studying custfcgi and fpapache units to see how they are written and 
it seems pretty straight forward though I have a couple of questions.  First, 
the basic logic is pretty easy to follow.  The TCustomWebApplication is the 
basic application object that is used and is composed with a TWebHandler 
descendant which is instantiated through .InitializeWebHandler and does most of 
the work of communicating with the client process, creating the TRequest and 
TResponse object to be pass to the appropriate TfpWebModule.

1. TWebHandler.GetApplicationURL.
I assume this is the base url root directory from the perspective of the client. 
  www.google.com would be the base url for instance.

2. TWebHandler.WaitForRequest vs. TWebHandler.HandleRequest.
Judging from the source in both custfcgi and fpapache units, it looks like they 
are optional to use one or the other?  TApacheHandler uses a dummy/fall through 
method for WaitForRequest and instead implements logic in .HandleRequest. 
TFCGIHandler on the other hand, uses WaitForRequest and implements logic there 
while not implementing .HandleRequest method at all.  Which one would be most 
optimal to use?  It looks to me that for a synapse server like I have, 
.WaitForRequest would be the choice here?

3. Handling TRequest and TResponse objects.

3a) I may be hitting a brain fart here, but who is responsible for destroying 
the TRequest and TResponse objects?

3b) What is the format for populating TRequest object with variables like get 
vars, http headers, etc?  I've been looking around the source, and I haven't yet 
found where this is happening :-)

4) What is the protocol for using a restful type url like this?

http://mysite.com/module-name/function-name/var1/var2/var3

5) For those instances where I need to build a page or fragment of html through 
code, which unit is recommended?  There seems to be some overlap between 
fcl-xml/dom_html.pp and fcl-xml/htmlelements.pp.

More questions to come I'm sure, but in the meantime, any help is as always, 
appreciated.

--
Warm Regards,

Lee








More information about the Lazarus mailing list