Squeak, NT, CGI and Microsofts web server?
Stefan Matthias Aust
sma at 3plus4.de
Sat Jun 17 10:50:31 UTC 2000
At 22:37 15.06.00 -0400, David T. Lewis wrote:
>Don't spend too much time paring down the image, I believe that Stefan is
>suggesting fastcgi so you do not need to worry about this.
Yes, one persistent image process would serve all requests.
>I have no real experience beyond this. Perhaps someone can suggest a perl
>or C way to glue a Squeak image to the back of a Microsoft or Apach web
>server, such that Squeak would be talking to socket connections, and the
>web server would think it was talking to fastcgi or some such thing.
That's basically what fastcgi provides. If you however don't need all
information, just the URL passed to the cgi program plus a few hand-picked
environment variables as well as in the case of http POST the passed data,
a small perl (or C) cgi program might be enough - assuming that this would
be fast enough if started for each request.
Squeak would implement a server socket, waiting for requests from the glue
program on a given port. Squeak would then process that request - at best
in a separate process but as all that sockets stuff is so much more
difficult than in Java I don't know whether that's possible - and reply
with a response sent back to the cgi program which in turn would use that
as its own response.
The request format could look like this. A header consisting of simple
lines, separated by crlf, and an optional body in the case of HTTP requests
which have data attached.
12 (number of key/value pairs following)
METHOD
GET
URL
... (whatever url was passed)
ENV
value (a number of other hand-picked environment variables)
12345 (number of data bytes following)
data
This is quite similar to a real HTTP request but hopefully easier to
generate for the cgi script and easier to parse for Squeak. For example:
n := stream nextLine asNumber.
env := Dictionary new: n.
n timesRepeat: [
key := stream nextLine.
value := stream nextLine copyReplace: '\n' with: Character cr.
env at: key put: value].
data := stream next: stream nextLine asNumber
Squeak will reply with a valid HTTP response and then close the socket. If
it can't read the header, an appropriate error (500 or so) is reported.
The CGI program should work like this (but of course not in Smalltalk)
"Setup environment variables, providing some defaults so that
it's consistent for Squeak. Note that we don't try to parse
anything here. 'environ' shall be the system environment,
'args' an array of command line parameters"
pairs := Dictionary new.
pairs
at: 'METHOD'
put: (envrion at: 'REQUEST_METHOD' ifAbsent: ['GET']).
pairs
at: 'URL'
put: (environ at: 'QUERY_STRING' ifAbsent: args first).
pairs
at: 'TYPE'
put: (environ at: 'CONTENT_TYPE' ifAbsent: '').
environ
at: 'AUTH_TYPE'
ifPresent: [:v | pairs at: 'AUTH_TYPE' put: v].
"etc..."
"Prepare the request emitting it to a socket 'stream'.
Note that we have to replace CRs with \n in values.
'input' is a stream the CGI gets the data passed, normally
stdin."
stream nextPutAll: pairs size asString; cr.
pairs keysAndValuesDo: [:k :v |
stream nextPutAll: k; cr.
stream nextPutAll:
((v copyReplace: '\' with: '\\')
copyReplace: Character cr asString with: '\n'); cr].
length := (environ at: 'CONTENT_LENGTH' ifAbsent: '0') asNumber.
stream nextPutAll: length asString; cr.
stream nextPutAll: (input next: length).
stream flush.
If somebody actually implements this (especially the perl or C part), I'd
like to get a copy. Or pay me to implement this strategy as open source
software ;-)
bye
--
Stefan Matthias Aust // Bevor wir fallen, fallen wir lieber auf
More information about the Squeak-dev
mailing list
|