[core] return from http_response_read if small rd
[lighttpd.git] / doc / outdated / state.txt
blob5e8277bd2aec55ba72ea0e0bf36deae86558266c
1 ============================
2 The State Engine of lighttpd
3 ============================
5 ------------
6 Module: core
7 ------------
9 :Author: Jan Kneschke
10 :Date: $Date: 2004/08/01 07:01:29 $
11 :Revision: $Revision: 1.1 $
13 :abstract:
14   This is a short summary of the state-engine which is driving the lighttpd
15   webserver. It describes the basic concepts and the way the different parts
16   of the server are connected.
18 .. meta::
19   :keywords: lighttpd, state-engine
21 .. contents:: Table of Contents
23 Description
24 ===========
26 States
27 ------
29 The state-engine is currently made of 11 states which are walk-through on
30 the way each connection. Some of them are specific for a special operation
31 and some may never be hit at all.
33 :connect:
34   waiting for a connection
35 :reqstart:
36   init the read-idle timer
37 :read:
38   read http-request-header from network
39 :reqend:
40   parse request
41 :readpost:
42   read http-request-content from network
43 :handlereq:
44   handle the request internally (might result in sub-requests)
45 :respstart:
46   prepare response header
47 :write:
48   write response-header + content to network
49 :respend:
50   cleanup environment, log request
51 :error:
52   reset connection (incl. close())
53 :close:
54   close connection (handle lingering close)
56 .. image:: state.png
58 A simple GET request (green path)
59 ---------------------------------
61 The connection is idling in the 'connect' state waiting for a connection.
62 As soon as the connection is set up we init the read-timer in 'reqstart'
63 and start to read data from the network. As soon as we get the
64 HTTP-request terminator (CRLFCRLF) we forward the header to the parser.
66 The parsed request is handled by 'handlereq' and as soon as a decision out
67 the request is made it is sent to 'respstart' to prepare the
68 HTTP-response header. In the 'write' state the prepare content is sent out
69 to the network. When everything is sent 'respend' is entered to log the
70 request and cleanup the environment. After the close() call the connection
71 is set back to the 'connect' state again.
73 Keep-Alive (blue path)
74 ----------------------
76 The Keep-Alive handling is implemented by going from the 'respend'
77 directly to 'reqstart' without the close() and the accept() calls.
79 POST requests (grey path)
80 -------------------------
82 As requests might contain a request-body the state 'readpost' entered as
83 soon as the header is parsed and we know how much data we expect.
85 Pipelining
86 ----------
88 HTTP/1.1 supportes pipelining (sending multiple requests without waiting
89 for the response of the first request). This is handled transparently by
90 the 'read' state.
92 Unexpected errors (red path)
93 ----------------------------
95 For really hard errors we use the 'error' state which resets the
96 connection and can be call from every state. It is only use if there is no
97 other way to handle the issue (e.g. client-side close of the connection).
98 If possible we should use http-status 500 ('internal server error') and
99 log the issue in the errorlog.
101 If we have to take care of some data which is coming in after we ran into
102 the error condition the 'close' state is used the init a half-close and
103 read all the delay packet from the network.
105 Sub-Requests (lightblue)
106 ------------------------
108 The FastCGI, CGI, ... intergration is done by introducing a loop in
109 'handlereq' to handle all aspect which are neccesary to find out what has
110 to be sent back to the client.
112 Functions
113 =========
115 Important functions used by the state-engine
117 :state-engine:
119 - ``connection_state_machine()``
121 :connect:
123 - (nothing)
125 :reqstart:
127 - (nothing)
129 :read:
131 - ``connection_handle_read_state()``
132 - ``connection_handle_read()``
134 :reqend:
136 - ``http_request_parse()``
138 :readpost:
140 - ``connection_handle_read_state()``
141 - ``connection_handle_read()``
143 :handlereq:
145 - ``http_response_prepare()``
147 :respstart:
149 - ``connection_handle_write_prepare()``
151 :write:
153 - ``connection_handle_write()``
155 :respend:
157 - ``plugins_call_handle_request_done()``
158 - ``plugins_call_handle_connection_close()``
159 - ``connection_close()`` (if not keep-alive)
160 - ``connection_reset()``
162 :error:
164 - ``plugins_call_handle_request_done()``
165 - ``plugins_call_handle_connection_close()``
166 - ``connection_reset()``
168 :close:
170 - ``connection_close()``