| Up - Design | Back - Processes handling | Forward - API Library |
AF_UNIX sockets and TCP/IP sockets, although while
local processes, started by the server and connected through
pipes don't require any authentication (if
their executables are at their places in the filesystem, they
definitely are created by some user, who has at least write
access to them), remote processes are required to pass their
names and username/password authentication information. The
protocol is binary and uses 32-bit integers with network byte
order, where applicable. Login sequence is character-based.
Local applications, connected through pipes or AF_UNIX sockets never use login sequence.
All messages in the login sequence are ASCII strings with
<CR><LF> line delimiters. Client sends
ASCII strings with <LF> or
<CR><LF> line delimiters. General
format of the message is the same as used in FTP protocol, so
message identification by the client should be performed by
the numeric response code.
fhttpd-decls.h file as
PROCESSSERVER in the current implementation)."220 Process server ready.""USER",
<SP> and the username."331 Password required
for username." means that
PASS command
should be used, "230 User username
logged in." finishes the user authentication. All
other responses are negative.PASS is required, client sends to the server
"PASS", <SP> and the
password. Otherwise, skips to the step 7."230 User
username logged in." finishes the user
authentication, all other responses are negative."APPLICATION",
<SP> and the application name."200 OK" finishes the
application login sequence, all other responses are
negative.
<LF>s are sent from both server and client)
binary protocol is used.
buffsize(32 bits) | id(32 bits) | reqtype(32 bits) |
rlsize(32 bits) | rl( rlsize bytes) | |
nlines(32 bits) |
lines( nlines line blocks) | |
databuffsize(32 bits) | data( databuffsize bytes) | |
where:
buffsize
id
reqtype
rlsize
rl
nlines
lines
nlines
line blocksdatabuffsize
data
| Value | Defined as | Meaning |
|---|---|---|
| 1 | FHTTPD_REQUEST | Request received from the HTTP client |
| 2 | FHTTPD_DISCONNECT | HTTP client disconnected |
| 3 | FHTTPD_ACK | Acknowledge for sent block(s) |
| 4 | FHTTPD_EXITOK | Confirmation for exit request |
paramc(32 bits) |
psize1(32 bits) | param1( psize1bytes) |
psize2(32 bits) | param2( psize2bytes) |
... | psizeparamc-1(32 bits) | paramparamc-1( psizeparamc-1bytes) |
where:
paramc
psizen
n-th parameterparamn
n-th parameterbuffsize(32 bits) | opnumber(32 bits) | id(32 bits) | data( buffsize-24 bytes) |
where:
buffsize
id
opnumber
| Value | Defined as | Meaning |
|---|---|---|
| 0 | FHTTPD_FINISH | Finish response (no data) |
| 1 | FHTTPD_SEND | Send the provided data to the client |
| 2 | FHTTPD_INST_SELECT | Set instance selection for the provided data |
| 3 | FHTTPD_INST_DESELECT | Remove instance selection for the provided data |
| 4 | FHTTPD_INST_CAP | Set capabilities (data is a 32-bit integer containing bit-mapped capabilities) |
| 5 | FHTTPD_FINISH_DROP | Finish response (no data) and disconnect the client. |
| 6 | FHTTPD_INST_EXITREQ | Exit request (data is a 32-bit integer containing the request value ) |
| Value | Defined as | Meaning |
|---|---|---|
| 1 | APP_CAP_KEEPALIVE | "Keep-Alive" option supported |
| 2 | APP_CAP_ACKFINISH | Send
FHTTPD_ACK message for blocks after finishing sending them |
stdin. Currently all lines in
parameters list have two parameters - key
and value. Keys are:"HTTP_ACCEPT"
Accept
field in the HTTP request"HTTP_IF_MODIFIED_SINCE"
If-Modified-Since
field in the HTTP request converted to the integer time value"HTTP_USER_AGENT"
User-Agent
field in the HTTP request"REMOTE_ADDR"
"REMOTE_HOST"
"REMOTE_USER"
"QUERY_STRING"
"CONTENT_LENGTH"
Content-length
field in the HTTP request (redundant, data buffer size
contains the same value)"CONTENT_TYPE"
Content-type
field in the HTTP request"SERVER_PROTOCOL"
HTTP/0.9 and HTTP/1.0 are supported)
"REQUEST_METHOD"
GET, HEAD and PODT are supported,
PUT is still reserved)"SERVER_PORT"
"SERVER_SOFTWARE"
"fhttpd/0.3.2")"GATEWAY_INTERFACE"
"CGI/1.1")"SERVER_NAME"
"SCRIPT_NAME"
"SCRIPT_NAME_RESOLVED"
"HTTP_whatever"
"KEEPALIVE"
"Y" if Keep-Alive
option is usedFHTTPD_FINISHFHTTPD_SENDFHTTPD_FINISH
message will be sent. Server doesn't parse the data.
FHTTPD_INST_SELECTFHTTPD_INST_DESELECTFHTTPD_INST_CAPFHTTPD_FINISH_DROPFHTTPD_EXITREQ
Requests are passed to processes in FHTTPD_REQUEST
messages. If process is connected through AF_UNIX
socket it may also receive a file handle of the socket, connected
to the client. Requests are sent until the number of requests,
sent to the instance and not completely answered by it reaches the
queue limit, and if the queue limit is 1, only one requests can be
sent to the instance at a time. Process should answer to the
client and finish serving the request by sending
FHTTPD_FINISH or FHTTPD_FINISH_DROP.
Data can be sent to the server in one or multiple
FHTTPD_SEND messages or to the client directly if
file descriptor is passed. If file descriptor was passed it should
be closed after sending the response through it or at any time
before FHTTPD_FINISH or
FHTTPD_FINISH_DROP is sent if
FHTTPD_SEND messages were used instead of it.
Since instance selection is done in the server, some mechanism
should determine situations, where such requests handling is
necessary and give the server the data, by which instances will
be selected. In HTTP there are three possible ways to positively
identify the session:
Identification using hidden fields in forms isn't supported in fhttpd because the design of fhttpd was based on the assumption that the data, passed from the client can be anything, not necessary a form input, and the server shouldn't parse it even if it is a form.
HTTP cookies while being the most clean and reliable way to handle sessions, aren't supported by all HTTP clients, so both cookie-based and "ugly" URLs with session identifiers are supported.
To establish an instance selection, user process sends to the
HTTP server FHTTPD_INST_SELECT message with 2 or 3
parameters in the data, separated by the <LF>:
'A'
"true" will be sent to this instance.'R'
"true" will
NOT be sent to this instance.'H'
'L'
'E'
"true" if the wildcard
expression matches with the argument and
"false" otherwise.'N'
"false" if the wildcard
expression matches with the argument and
"true" otherwise.
Wildcard matching uses the same rules as shell wildcard
matching, except for slash ('/') having no special
meaning.
For the identifier in the HTTP cookie the request can be
"AHE\nHTTP_COOKIE\nCSES=value*", and
for the identifier in the URL the request can be
"ALE\n*?CSES=value*"
where "CSES" is the cookie key ("Client SESsion")
and value is the cookie value. It's assumed that value
doesn't contain any special characters for wildcard matching (or
they are backslash-escaped) and has delimiters as first and last
characters (the API library generates such cookies by itself).
APP_CAP_ACKFINISH capability to get notified about
blocks sent to the client. by FHTTPD_ACK
messages. These messages contain no parameters and data is a
32-bit integer containing the number of buffers sent in response
to some request (where request ID in the message indicates
request) since the last FHTTPD_ACK message
about the same request or since the beginning in the first
message. Server does not guarantee that FHTTPD_ACK
will be sent for every buffer, but it provides the number of sent
buffers for the case when multiple buffers were written at
once. It should be noted that "sent" doesn't mean that the data is
actually arrived at the client or even was sent through the network
interface -- buffering and delays obscure exact timing -- although
for flow control needs it's enough.
Clean exit procedure requires sending an exit request and wait for a confirmation:
FHTTPD_INST_EXITREQ
request with nonzero value to the server.FHTTPD_EXITOK to it.
At any time after FHTTPD_INST_EXITREQ request is sent
process can send FHTTPD_INST_EXITREQ request with
the value 0 to the server to cancel the exit request. That will
cause HTTP server to continue sending requests to the process.
| Up - Design | Back - Processes handling | Forward - API Library |