Commit Graph

1371 Commits

Author SHA1 Message Date
Willy Tarreau
deb9ed8f60 [MEDIUM] config: remove the limitation of 10 reqadd/rspadd statements
Now we use a linked list, there is no limit anymore.
2010-01-03 21:22:14 +01:00
Willy Tarreau
97cb780e81 [MINOR] config: centralize proxy struct initialization 2010-01-03 21:22:14 +01:00
Willy Tarreau
f285f54311 [MINOR] redirect: add support for unconditional rules
Sometimes it's useful to be able to specify an unconditional redirect
rule without adding "if TRUE".
2010-01-03 21:22:08 +01:00
Willy Tarreau
963abc33a2 [MINOR] config: some options were missing for "redirect"
Those options were missing in the parser error message :
  set-cookie, clear-cookie, drop-query
2010-01-03 19:49:34 +01:00
Willy Tarreau
305ae85957 [BUG] http: fix cookie parser to support spaces and commas in values
The cookie parser could be fooled by spaces or commas in cookie names
and values, causing the persistence cookie not to be matched if located
just after such a cookie. Now spaces found in values are considered as
part of the value, and spaces, commas and semi-colons found in values
or names, are skipped till next cookie name.

This fix must be backported to 1.3.
2010-01-03 19:45:54 +01:00
Krzysztof Piotr Oledzki
6492db5453 [BUG] Healthchecks: get a proper error code if connection cannot be completed immediately
In case of a non-blocking socket, used for connecting to a remote
server (not localhost), the error reported by the health check
was most of a time one of EINPROGRESS/EAGAIN/EALREADY.

This patch adds a getsockopt(..., SO_ERROR, ...) call so now
the proper error message is reported.
2010-01-03 19:23:19 +01:00
Willy Tarreau
a9679ac94b [MINOR] http: make the conditional redirect support keep-alive
It makes sense to permit a client to keep its connection when
performing a redirect to the same host. We only detect the fact
that the redirect location begins with a slash to use the keep-alive
(if the client supports it).
2010-01-03 17:32:57 +01:00
Willy Tarreau
2be3939416 [MINOR] http: don't wait for sending requests to the server
By default we automatically wait for enough data to fill large
packets if buf->to_forward is not null. This causes a problem
with POST/Expect requests which have a data size but no data
immediately available. Instead of causing noticeable delays on
such requests, simply add a flag to disable waiting when sending
requests.
2010-01-03 17:24:51 +01:00
Willy Tarreau
6c2cbe14e4 [BUG] http: take care of errors, timeouts and aborts during the data phase
In server-close mode particularly, the response buffer is marked for
no-auto-close after a response passed through. This prevented a POST
request from being aborted on errors, timeouts or anything if the
response was received before the request was complete.
2010-01-03 17:07:49 +01:00
Willy Tarreau
bc5aa19e97 [MINOR] http: move redirect messages to HTTP/1.1 with a content-length
This is cleaner and this tells clients we support 1.1.
2010-01-03 15:12:05 +01:00
Willy Tarreau
5e8949cf84 [OPTIM] http: don't immediately enable reading on request
If we enable reading of a request immediately after completing
another one, we end up performing small reads until the request
buffer is complete. This takes time and makes it harder to realign
the buffer when needed. Just enable reading when we need to.
2010-01-03 14:54:32 +01:00
Willy Tarreau
a95a1f4614 [BUG] http: the request URI pointer is relative to the buffer
The rq.u field is relative to buf->data, not to msg->sol. We have
to subtract msg->som everywhere this error was made. Maybe it will
be simpler to have a pointer to the buffer in the message and find
appropriate data there.
2010-01-03 13:04:35 +01:00
Willy Tarreau
3bb9c23bd6 [BUG] http: redirects were broken by chunk changes
Redirects used to initialize a chunk whose size was not set (0).
Also, the return code of chunk_strcpy() is 1 in case of success.
2010-01-03 12:24:37 +01:00
Willy Tarreau
face839296 [OPTIM] http: set MSG_MORE on response when a pipelined request is pending
Many times we see a lot of short responses in HTTP (typically 304 on a
reload). It is a waste of network bandwidth to send that many small packets
when we know we can merge them. When we know that another HTTP request is
following a response, we set BF_EXPECT_MORE on the response buffer, which
will turn MSG_MORE on exactly once. That way, multiple short responses can
leave pipelined if their corresponding requests were also pipelined.
2010-01-03 11:37:54 +01:00
Willy Tarreau
d38b53b896 [MINOR] stream_sock: enable MSG_MORE when forwarding finite amount of data
While it could be dangerous to enable MSG_MORE on infinite data (eg:
interactive sessions), it makes sense to enable it when we know the
chunk to be sent is just a part of a larger one.
2010-01-03 11:18:34 +01:00
Willy Tarreau
638cd02e9d [BUG] http: fix erroneous trailers size computation
We used to forward more trailers than required, causing a
desynchronization of the output. Now we schedule all for forwarding
as soon as we encounter them.
2010-01-03 07:42:04 +01:00
Willy Tarreau
21c5e4d85b [BUG] last fix was overzealous and disabled server-close
we must not close on remote shutdown but on remote error only.
2010-01-03 00:19:31 +01:00
Willy Tarreau
082b01c541 [BUG] http: ensure we abort data transfer on write error
When a write error is encountered during a data phase, we must
absolutely abort the pending data transfer, otherwise it will
never complete.
2010-01-03 00:00:45 +01:00
Willy Tarreau
b608feb82a [MAJOR] http: add support for option http-server-close
This option enables HTTP keep-alive on the client side and close mode
on the server side. This offers the best latency on the slow client
side, and still saves as many resources as possible on the server side
by actively closing connections. Pipelining is supported on both requests
and responses, though there is currently no reason to get pipelined
responses.
2010-01-02 22:47:18 +01:00
Willy Tarreau
2ab6eb1e24 [MEDIUM] http: make the parsers able to wait for a buffer flush
When too large a message lies in a buffer before parsing a new
request/response, we can now wait for previous outgoing data to
leave the buffer before attempting to parse again. After that
we can consider the opportunity to realign the buffer if needed.
2010-01-02 22:04:45 +01:00
Willy Tarreau
15de77e16e [MEDIUM] http: make the analyser not rely on msg being initialized anymore
The HTTP parser needed the msg structure to hold pre-initialized pointers.
This causes a trouble with keep-alive because if some data is still in the
buffer, the pointers can be anywhere after the data and later become invalid
when the buffer gets realigned.

It was not needed to rely on that since we have two valid information
in the buffer itself :

  - buf->lr : last visited place
  - buf->w + buf->send_max : beginning of next message

So by doing the maths only on those values, we can avoid doing tricks
on msg->som.
2010-01-02 21:59:16 +01:00
Willy Tarreau
0b9da8dd45 [BUILD] halog: insufficient include path in makefile 2010-01-02 12:23:30 +01:00
Willy Tarreau
a31e5dff36 [MINOR] config: option forceclose is valid in frontends too
This option was disabled for frontends in the configuration because
it was useless in its initial implementation, though it was still
checked in the code. Let's officially enable it now.
2009-12-30 01:10:35 +01:00
Willy Tarreau
c88ea68ef1 [MEDIUM] http: add some SI_FL_NOLINGER around server errors
When we catch an error from the server, speed up the connection
abort since we don't want to remain long with pending data in the
socket, and we want to be able to reuse our source port ASAP.
2009-12-29 14:56:36 +01:00
Willy Tarreau
1464140fce [MEDIUM] session: set SI_FL_NOLINGER when aborting on write timeouts
Doing this helps us flush the system buffers from all unread data. This
avoids having orphans when clients suddenly get off the net without
reading their entire response.
2009-12-29 14:49:56 +01:00
Willy Tarreau
9438c718ce [MEDIUM] http: make forceclose use SI_FL_NOLINGER
Option forceclose is not limited to the shortage of source ports
anymore thanks to this flag.
2009-12-29 14:39:48 +01:00
Willy Tarreau
4c283dce4b [MINOR] stream_sock: add SI_FL_NOLINGER for faster close
This new flag may be set by any user on a stream interface to tell
the underlying protocol that there is no need for lingering on the
socket since we know the other side either received everything or
does not care about what we sent.

This will typically be used with forced server close in HTTP mode,
where we want to quickly close a server connection after receiving
its response. Otherwise the system would prevent us from reusing
the same port for some time.
2009-12-29 14:36:34 +01:00
Willy Tarreau
82eeaf2fae [MEDIUM] http: properly handle "option forceclose"
The "forceclose" option used to close the output channel to the
server once it started to respond. While this happened to work with
most servers, some of them considered this as a connection abort and
immediately stopped responding.

Now that we're aware of the end of a request and response, we're able
to trivially handle this option and properly close both sides when the
server's response is complete.

During this change it appeared that forwarding could be allowed when
the BF_SHUTW_NOW flag was set on a buffer, which obviously is not
acceptable and was causing some trouble. This has been fixed too and
is the reason for the MEDIUM status on this patch.
2009-12-29 14:26:42 +01:00
Willy Tarreau
5523b32cc6 [MEDIUM] http: add two more states for the closing period
HTTP_MSG_CLOSING and HTTP_MSG_CLOSED are needed to know when it
is safe to close a connection without risking to destroy pending
data.
2009-12-29 12:05:52 +01:00
Willy Tarreau
33b2db69a9 [MINOR] stream_sock: prepare for closing when all pending data are sent
Since we'll soon be able to close a connection with remaining data in a
buffer, it becomes obvious that we can prepare to close when we're about
to send the last chunk of data and not the whole buffer.
2009-12-29 08:02:56 +01:00
Willy Tarreau
019fd5bc93 [BUG] buffers: wrong size calculation for displaced data
This error was triggered by requests not starting at the beginning
of the buffer. It cannot happen with earlier versions though it might
be a good idea to fix it anyway.
2009-12-28 18:37:54 +01:00
Willy Tarreau
83e3af0c86 [MEDIUM] http: rework the buffer alignment logic
There were still issues with the buffer alignment. Now we ensure
that we always align it before a request or response is completely
parsed if there is less than maxrewrite bytes free at the end. In
practice, it's not called that often and ensures we can always work
as expected.
2009-12-28 17:39:57 +01:00
Willy Tarreau
864e8256ec [BUG] stream_sock: wrong max computation on recv
Since the introduction of the automatic sizing of buffers during reads,
a bug appeared where the max size could be negative, causing large
chunks of memory to be overwritten during recv() calls if a read pointer
was already past the buffer's limit.
2009-12-28 17:36:37 +01:00
Willy Tarreau
58cc872848 [BUG] http: typos on several unlikely() around header insertion
In many places where we perform header insertion, an error control
is performed but due to a mistake, it cannot match any error :

   if (unlikely(error) < 0)
instead of
   if (unlikely(error < 0))

This prevents error 400 responses from being sent when the buffer is
full due to many header additions. This must be backported to 1.3.
2009-12-28 06:57:33 +01:00
Willy Tarreau
d98cf93395 [MAJOR] http: implement body parser
The body parser will be used in close and keep-alive modes. It follows
the stream to keep in sync with both the request and the response message.
Both chunked transfer-coding and content-length are supported according to
RFC2616.

The multipart/byterange encoding has not yet been implemented and if not
seconded by any of the two other ones, will be forwarded till the close,
as requested by the specification.

Both the request and the response analysers converge into an HTTP_MSG_DONE
state where it will be possible to force a close (option forceclose) or to
restart with a fresh new transaction and maintain keep-alive.

This change is important. All tests are OK but any possible behaviour
change with "option httpclose" might find its root here.
2009-12-27 22:54:55 +01:00
Willy Tarreau
5d881d0f3a [MINOR] new function stream_int_cond_close()
This one will be used to conditionally send a message upon a
close on a stream interface. It will not overwrite any existing
data.
2009-12-27 22:51:06 +01:00
Willy Tarreau
7c96f678fa [BUG] http: body parsing must consider the start of message
When parsing body for URL parameters, we must not consider that
data are available from buf->data but from buf->data + msg->som.
This is not a problem right now but may become with keep-alive.
2009-12-27 22:47:25 +01:00
Willy Tarreau
aec571c2bb [MEDIUM] http: automatically re-aling request buffer
When parsing a request that does not start at the beginning of the
buffer, we may experience a buffer full issue. In order to avoid
this, we try to realign the buffer if it is not really full. That
will be required when we have to deal with pipelined requests.
2009-12-27 17:18:11 +01:00
Willy Tarreau
1d3bcce4dd [BUG] http: offsets are relative to the buffer, not to ->som
Some wrong operations were performed on buffers, assuming the
offsets were relative to the beginning of the request while they
are relative to the beginning of the buffer. In practice this is
not yet an issue since both are the same... until we add support
for keep-alive.
2009-12-27 15:50:06 +01:00
Willy Tarreau
d21e01c63f [MINOR] buffers: add buffer_ignore() to skip some bytes
This simple function will be used to skip blanks at the beginning of a
request or response.
2009-12-27 15:45:38 +01:00
Willy Tarreau
e8e785bb85 [MEDIUM] http: add a new transaction flags indicating if we know the transfer length
It's not enough to know if the connection will be in CLOSE or TUNNEL mode,
we still need to know whether we want to read a full message to a known
length or read it till the end just as in TUNNEL mode. Some updates to the
RFC clarify slightly better the corner cases, in particular for the case
where a non-chunked encoding is used last.

Now we also take care of adding a proper "connection: close" to messages
whose size could not be determined.
2009-12-26 16:29:04 +01:00
Willy Tarreau
115acb9755 [MEDIUM] http: rework chunk-size parser
Chunked encoding can be slightly more complex than what was implemented.
Specifically, it supports some optional extensions that were not parsed
till now if present, and would have caused an error to be returned.

Also, now we enforce check for too large values in chunk sizes in order
to ensure we never overflow.

Last, we're now able to return a request error if we can't read the
chunk size because the buffer is already full.
2009-12-26 13:56:06 +01:00
Willy Tarreau
0394594b06 [MINOR] http: introduce a new synchronisation state : HTTP_MSG_DONE
This state indicates that an HTTP message (request or response) is
complete. This will be used to know when we can re-initialize a
new transaction. Right now we only switch to it after the end of
headers if there is no data. When other analysers are implemented,
we can switch to this state too.

The condition to reuse a connection is when the response finishes
after the request. This will have to be checked when setting the
state.
2009-12-22 16:50:27 +01:00
Willy Tarreau
63c9e5ffa6 [MINOR] http: move 1xx handling earlier to eliminate a lot of ifs
The response 1xx was set too low and required a lot of tests along
the code in order to avoid some processing. We still left the test
after the response rewrite rules so that we can eliminate unwanted
headers if required.
2009-12-22 16:01:27 +01:00
Willy Tarreau
0937bc43cf [MINOR] http: move the http transaction init/cleanup code to proto_http
This code really belongs to the http part since it's transaction-specific.
This will also make it easier to later reinitialize a transaction in order
to support keepalive.
2009-12-22 15:03:09 +01:00
Willy Tarreau
7c3c54177a [MAJOR] buffers: automatically compute the maximum buffer length
We used to apply a limit to each buffer's size in order to leave
some room to rewrite headers, then we used to remove this limit
once the session switched to a data state.

Proceeding that way becomes a problem with keepalive because we
have to know when to stop reading too much data into the buffer
so that we can leave some room again to process next requests.

The principle we adopt here consists in only relying on to_forward+send_max.
Indeed, both of those data define how many bytes will leave the buffer.
So as long as their sum is larger than maxrewrite, we can safely
fill the buffers. If they are smaller, then we refrain from filling
the buffer. This means that we won't risk to fill buffers when
reading last data chunk followed by a POST request and its contents.

The only impact identified so far is that we must ensure that the
BF_FULL flag is correctly dropped when starting to forward. Right
now this is OK because nobody inflates to_forward without using
buffer_forward().
2009-12-22 10:06:34 +01:00
Willy Tarreau
9e13c3c630 [MINOR] http: only consider chunk encoding with HTTP/1.1
This must be ignored in case of HTTP/1.0.
2009-12-22 09:59:58 +01:00
Willy Tarreau
5b15447672 [MAJOR] http: completely process the "connection" header
Up to now, we only had a flag in the session indicating if it had to
work in "connection: close" mode. This is not at all compatible with
keep-alive.

Now we ensure that both sides of a connection act independantly and
only relative to the transaction. The HTTP version of the request
and response is also correctly considered. The connection already
knows several modes :
  - tunnel (CONNECT or no option in the config)
  - keep-alive (when permitted by configuration)
  - server-close (close the server side, not the client)
  - close (close both sides)

This change carefully detects all situations to find whether a request
can be fully processed in its mode according to the configuration. Then
the response is also checked and tested to fix corner cases which can
happen with different HTTP versions on both sides (eg: a 1.0 client
asks for explicit keep-alive, and the server responds with 1.1 without
a header).

The mode is selected by a capability elimination algorithm which
automatically focuses on the least capable agent between the client,
the frontend, the backend and the server. This ensures we won't get
undesired situtations where one of the 4 "agents" is not able to
process a transaction.

No "Connection: close" header will be added anymore to HTTP/1.0 requests
or responses since they're already in close mode.

The server-close mode is still not completely implemented. The response
needs to be rewritten as keep-alive before being sent to the client if
the connection was already in server-close (which implies the request
was in keep-alive) and if the response has a content-length or a
transfer-encoding (but only if client supports 1.1).

A later improvement in server-close mode would probably be to detect
some situations where it's interesting to close the response (eg:
redirections with remote locations). But even then, the client might
close by itself.

It's also worth noting that in tunnel mode, no connection header is
affected in either direction. A tunnelled connection should theorically
be notified at the session level, but this is useless since by definition
there will not be any more requests on it. Thus, we don't need to add a
flag into the session right now.
2009-12-22 09:52:43 +01:00
Willy Tarreau
157dd638e9 [MEDIUM] backend: remove HTTP POST parsing from get_server_ph_post()
Now that the HTTP analyser will already have parsed the beginning
of the request body, we don't have to check for transfer-encoding
anymore since we have the current chunk size in hdr_content_len.
2009-12-22 09:52:42 +01:00
Willy Tarreau
522d6c048f [MEDIUM] http: process request body in a specific analyser
The POST body analysis was split between two analysers for historical
reasons. Now we only have one analyser which checks content length
and waits for enough data to come.

Right now this analyser waits for <url_param_post_limit> bytes of
body to reach the buffer, or the first chunk. But this could be
improved to wait for any other amount of data or any specific
contents.
2009-12-22 09:52:42 +01:00