2006-06-26 00:48:02 +00:00
|
|
|
/*
|
2009-10-04 13:56:38 +00:00
|
|
|
* include/proto/proto_http.h
|
|
|
|
* This file contains HTTP protocol definitions.
|
|
|
|
*
|
2011-01-06 16:51:27 +00:00
|
|
|
* Copyright (C) 2000-2011 Willy Tarreau - w@1wt.eu
|
2009-10-04 13:56:38 +00:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation, version 2.1
|
|
|
|
* exclusively.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
*/
|
2006-06-26 00:48:02 +00:00
|
|
|
|
|
|
|
#ifndef _PROTO_PROTO_HTTP_H
|
|
|
|
#define _PROTO_PROTO_HTTP_H
|
|
|
|
|
2006-06-29 16:54:54 +00:00
|
|
|
#include <common/config.h>
|
2015-09-10 16:28:10 +00:00
|
|
|
#include <types/action.h>
|
2006-06-26 00:48:02 +00:00
|
|
|
#include <types/proto_http.h>
|
REORG/MAJOR: session: rename the "session" entity to "stream"
With HTTP/2, we'll have to support multiplexed streams. A stream is in
fact the largest part of what we currently call a session, it has buffers,
logs, etc.
In order to catch any error, this commit removes any reference to the
struct session and tries to rename most "session" occurrences in function
names to "stream" and "sess" to "strm" when that's related to a session.
The files stream.{c,h} were added and session.{c,h} removed.
The session will be reintroduced later and a few parts of the stream
will progressively be moved overthere. It will more or less contain
only what we need in an embryonic session.
Sample fetch functions and converters will have to change a bit so
that they'll use an L5 (session) instead of what's currently called
"L4" which is in fact L6 for now.
Once all changes are completed, we should see approximately this :
L7 - http_txn
L6 - stream
L5 - session
L4 - connection | applet
There will be at most one http_txn per stream, and a same session will
possibly be referenced by multiple streams. A connection will point to
a session and to a stream. The session will hold all the information
we need to keep even when we don't yet have a stream.
Some more cleanup is needed because some code was already far from
being clean. The server queue management still refers to sessions at
many places while comments talk about connections. This will have to
be cleaned up once we have a server-side connection pool manager.
Stream flags "SN_*" still need to be renamed, it doesn't seem like
any of them will need to move to the session.
2015-04-02 22:22:06 +00:00
|
|
|
#include <types/stream.h>
|
2006-06-26 00:48:02 +00:00
|
|
|
#include <types/task.h>
|
2018-06-15 14:42:02 +00:00
|
|
|
#include <proto/channel.h>
|
2017-09-21 07:30:46 +00:00
|
|
|
#include <proto/h1.h>
|
2006-06-26 00:48:02 +00:00
|
|
|
|
2006-12-04 01:26:12 +00:00
|
|
|
/*
|
|
|
|
* some macros used for the request parsing.
|
2017-04-28 13:24:30 +00:00
|
|
|
* from RFC7230:
|
2006-12-04 01:26:12 +00:00
|
|
|
* CTL = <any US-ASCII control character (octets 0 - 31) and DEL (127)>
|
2007-01-21 18:16:41 +00:00
|
|
|
* SEP = one of the 17 defined separators or SP or HT
|
|
|
|
* LWS = CR, LF, SP or HT
|
|
|
|
* SPHT = SP or HT. Use this macro and not a boolean expression for best speed.
|
|
|
|
* CRLF = CR or LF. Use this macro and not a boolean expression for best speed.
|
|
|
|
* token = any CHAR except CTL or SEP. Use this macro and not a boolean expression for best speed.
|
2007-03-04 17:13:58 +00:00
|
|
|
*
|
|
|
|
* added for ease of use:
|
|
|
|
* ver_token = 'H', 'P', 'T', '/', '.', and digits.
|
2006-12-04 01:26:12 +00:00
|
|
|
*/
|
|
|
|
|
REORG/MAJOR: session: rename the "session" entity to "stream"
With HTTP/2, we'll have to support multiplexed streams. A stream is in
fact the largest part of what we currently call a session, it has buffers,
logs, etc.
In order to catch any error, this commit removes any reference to the
struct session and tries to rename most "session" occurrences in function
names to "stream" and "sess" to "strm" when that's related to a session.
The files stream.{c,h} were added and session.{c,h} removed.
The session will be reintroduced later and a few parts of the stream
will progressively be moved overthere. It will more or less contain
only what we need in an embryonic session.
Sample fetch functions and converters will have to change a bit so
that they'll use an L5 (session) instead of what's currently called
"L4" which is in fact L6 for now.
Once all changes are completed, we should see approximately this :
L7 - http_txn
L6 - stream
L5 - session
L4 - connection | applet
There will be at most one http_txn per stream, and a same session will
possibly be referenced by multiple streams. A connection will point to
a session and to a stream. The session will hold all the information
we need to keep even when we don't yet have a stream.
Some more cleanup is needed because some code was already far from
being clean. The server queue management still refers to sessions at
many places while comments talk about connections. This will have to
be cleaned up once we have a server-side connection pool manager.
Stream flags "SN_*" still need to be renamed, it doesn't seem like
any of them will need to move to the session.
2015-04-02 22:22:06 +00:00
|
|
|
int process_cli(struct stream *s);
|
|
|
|
int process_srv_data(struct stream *s);
|
|
|
|
int process_srv_conn(struct stream *s);
|
|
|
|
int http_wait_for_request(struct stream *s, struct channel *req, int an_bit);
|
|
|
|
int http_process_req_common(struct stream *s, struct channel *req, int an_bit, struct proxy *px);
|
|
|
|
int http_process_request(struct stream *s, struct channel *req, int an_bit);
|
|
|
|
int http_process_tarpit(struct stream *s, struct channel *req, int an_bit);
|
|
|
|
int http_wait_for_request_body(struct stream *s, struct channel *req, int an_bit);
|
2012-03-09 11:11:57 +00:00
|
|
|
int http_send_name_header(struct http_txn *txn, struct proxy* be, const char* svr_name);
|
REORG/MAJOR: session: rename the "session" entity to "stream"
With HTTP/2, we'll have to support multiplexed streams. A stream is in
fact the largest part of what we currently call a session, it has buffers,
logs, etc.
In order to catch any error, this commit removes any reference to the
struct session and tries to rename most "session" occurrences in function
names to "stream" and "sess" to "strm" when that's related to a session.
The files stream.{c,h} were added and session.{c,h} removed.
The session will be reintroduced later and a few parts of the stream
will progressively be moved overthere. It will more or less contain
only what we need in an embryonic session.
Sample fetch functions and converters will have to change a bit so
that they'll use an L5 (session) instead of what's currently called
"L4" which is in fact L6 for now.
Once all changes are completed, we should see approximately this :
L7 - http_txn
L6 - stream
L5 - session
L4 - connection | applet
There will be at most one http_txn per stream, and a same session will
possibly be referenced by multiple streams. A connection will point to
a session and to a stream. The session will hold all the information
we need to keep even when we don't yet have a stream.
Some more cleanup is needed because some code was already far from
being clean. The server queue management still refers to sessions at
many places while comments talk about connections. This will have to
be cleaned up once we have a server-side connection pool manager.
Stream flags "SN_*" still need to be renamed, it doesn't seem like
any of them will need to move to the session.
2015-04-02 22:22:06 +00:00
|
|
|
int http_wait_for_response(struct stream *s, struct channel *rep, int an_bit);
|
|
|
|
int http_process_res_common(struct stream *s, struct channel *rep, int an_bit, struct proxy *px);
|
|
|
|
int http_request_forward_body(struct stream *s, struct channel *req, int an_bit);
|
|
|
|
int http_response_forward_body(struct stream *s, struct channel *res, int an_bit);
|
2015-09-25 09:06:37 +00:00
|
|
|
void http_msg_analyzer(struct http_msg *msg, struct hdr_idx *idx);
|
2015-09-25 16:53:18 +00:00
|
|
|
void http_txn_reset_req(struct http_txn *txn);
|
|
|
|
void http_txn_reset_res(struct http_txn *txn);
|
2006-06-26 00:48:02 +00:00
|
|
|
|
REORG/MAJOR: session: rename the "session" entity to "stream"
With HTTP/2, we'll have to support multiplexed streams. A stream is in
fact the largest part of what we currently call a session, it has buffers,
logs, etc.
In order to catch any error, this commit removes any reference to the
struct session and tries to rename most "session" occurrences in function
names to "stream" and "sess" to "strm" when that's related to a session.
The files stream.{c,h} were added and session.{c,h} removed.
The session will be reintroduced later and a few parts of the stream
will progressively be moved overthere. It will more or less contain
only what we need in an embryonic session.
Sample fetch functions and converters will have to change a bit so
that they'll use an L5 (session) instead of what's currently called
"L4" which is in fact L6 for now.
Once all changes are completed, we should see approximately this :
L7 - http_txn
L6 - stream
L5 - session
L4 - connection | applet
There will be at most one http_txn per stream, and a same session will
possibly be referenced by multiple streams. A connection will point to
a session and to a stream. The session will hold all the information
we need to keep even when we don't yet have a stream.
Some more cleanup is needed because some code was already far from
being clean. The server queue management still refers to sessions at
many places while comments talk about connections. This will have to
be cleaned up once we have a server-side connection pool manager.
Stream flags "SN_*" still need to be renamed, it doesn't seem like
any of them will need to move to the session.
2015-04-02 22:22:06 +00:00
|
|
|
void debug_hdr(const char *dir, struct stream *s, const char *start, const char *end);
|
|
|
|
int apply_filter_to_req_headers(struct stream *s, struct channel *req, struct hdr_exp *exp);
|
|
|
|
int apply_filter_to_req_line(struct stream *s, struct channel *req, struct hdr_exp *exp);
|
|
|
|
int apply_filters_to_request(struct stream *s, struct channel *req, struct proxy *px);
|
|
|
|
int apply_filters_to_response(struct stream *s, struct channel *rtr, struct proxy *px);
|
|
|
|
void manage_client_side_cookies(struct stream *s, struct channel *req);
|
|
|
|
void manage_server_side_cookies(struct stream *s, struct channel *rtr);
|
2017-12-22 14:03:36 +00:00
|
|
|
void check_request_for_cacheability(struct stream *s, struct channel *chn);
|
REORG/MAJOR: session: rename the "session" entity to "stream"
With HTTP/2, we'll have to support multiplexed streams. A stream is in
fact the largest part of what we currently call a session, it has buffers,
logs, etc.
In order to catch any error, this commit removes any reference to the
struct session and tries to rename most "session" occurrences in function
names to "stream" and "sess" to "strm" when that's related to a session.
The files stream.{c,h} were added and session.{c,h} removed.
The session will be reintroduced later and a few parts of the stream
will progressively be moved overthere. It will more or less contain
only what we need in an embryonic session.
Sample fetch functions and converters will have to change a bit so
that they'll use an L5 (session) instead of what's currently called
"L4" which is in fact L6 for now.
Once all changes are completed, we should see approximately this :
L7 - http_txn
L6 - stream
L5 - session
L4 - connection | applet
There will be at most one http_txn per stream, and a same session will
possibly be referenced by multiple streams. A connection will point to
a session and to a stream. The session will hold all the information
we need to keep even when we don't yet have a stream.
Some more cleanup is needed because some code was already far from
being clean. The server queue management still refers to sessions at
many places while comments talk about connections. This will have to
be cleaned up once we have a server-side connection pool manager.
Stream flags "SN_*" still need to be renamed, it doesn't seem like
any of them will need to move to the session.
2015-04-02 22:22:06 +00:00
|
|
|
void check_response_for_cacheability(struct stream *s, struct channel *rtr);
|
2011-03-10 10:25:07 +00:00
|
|
|
int stats_check_uri(struct stream_interface *si, struct http_txn *txn, struct proxy *backend);
|
2006-12-24 16:47:20 +00:00
|
|
|
void init_proto_http();
|
2013-06-10 16:39:42 +00:00
|
|
|
int http_find_full_header2(const char *name, int len,
|
|
|
|
char *sol, struct hdr_idx *idx,
|
|
|
|
struct hdr_ctx *ctx);
|
2008-04-14 18:47:37 +00:00
|
|
|
int http_find_header2(const char *name, int len,
|
2010-01-18 13:54:04 +00:00
|
|
|
char *sol, struct hdr_idx *idx,
|
2008-04-14 18:47:37 +00:00
|
|
|
struct hdr_ctx *ctx);
|
2015-09-25 13:10:50 +00:00
|
|
|
int http_find_next_header(char *sol, struct hdr_idx *idx,
|
|
|
|
struct hdr_ctx *ctx);
|
2013-10-15 09:43:19 +00:00
|
|
|
char *find_hdr_value_end(char *s, const char *e);
|
2015-09-25 13:10:50 +00:00
|
|
|
char *extract_cookie_value(char *hdr, const char *hdr_end, char *cookie_name,
|
2018-07-13 08:54:26 +00:00
|
|
|
size_t cookie_name_l, int list, char **value, size_t *value_l);
|
2013-10-15 09:43:19 +00:00
|
|
|
int http_header_match2(const char *hdr, const char *end, const char *name, int len);
|
|
|
|
int http_remove_header2(struct http_msg *msg, struct hdr_idx *idx, struct hdr_ctx *ctx);
|
|
|
|
int http_header_add_tail2(struct http_msg *msg, struct hdr_idx *hdr_idx, const char *text, int len);
|
2015-04-03 23:09:08 +00:00
|
|
|
int http_replace_req_line(int action, const char *replace, int len, struct proxy *px, struct stream *s);
|
2017-01-01 21:10:52 +00:00
|
|
|
void http_set_status(unsigned int status, const char *reason, struct stream *s);
|
REORG/MAJOR: session: rename the "session" entity to "stream"
With HTTP/2, we'll have to support multiplexed streams. A stream is in
fact the largest part of what we currently call a session, it has buffers,
logs, etc.
In order to catch any error, this commit removes any reference to the
struct session and tries to rename most "session" occurrences in function
names to "stream" and "sess" to "strm" when that's related to a session.
The files stream.{c,h} were added and session.{c,h} removed.
The session will be reintroduced later and a few parts of the stream
will progressively be moved overthere. It will more or less contain
only what we need in an embryonic session.
Sample fetch functions and converters will have to change a bit so
that they'll use an L5 (session) instead of what's currently called
"L4" which is in fact L6 for now.
Once all changes are completed, we should see approximately this :
L7 - http_txn
L6 - stream
L5 - session
L4 - connection | applet
There will be at most one http_txn per stream, and a same session will
possibly be referenced by multiple streams. A connection will point to
a session and to a stream. The session will hold all the information
we need to keep even when we don't yet have a stream.
Some more cleanup is needed because some code was already far from
being clean. The server queue management still refers to sessions at
many places while comments talk about connections. This will have to
be cleaned up once we have a server-side connection pool manager.
Stream flags "SN_*" still need to be renamed, it doesn't seem like
any of them will need to move to the session.
2015-04-02 22:22:06 +00:00
|
|
|
int http_transform_header_str(struct stream* s, struct http_msg *msg, const char* name,
|
2015-03-16 10:15:50 +00:00
|
|
|
unsigned int name_len, const char *str, struct my_regex *re,
|
|
|
|
int action);
|
2016-05-18 14:17:44 +00:00
|
|
|
void inet_set_tos(int fd, const struct sockaddr_storage *from, int tos);
|
REORG/MAJOR: session: rename the "session" entity to "stream"
With HTTP/2, we'll have to support multiplexed streams. A stream is in
fact the largest part of what we currently call a session, it has buffers,
logs, etc.
In order to catch any error, this commit removes any reference to the
struct session and tries to rename most "session" occurrences in function
names to "stream" and "sess" to "strm" when that's related to a session.
The files stream.{c,h} were added and session.{c,h} removed.
The session will be reintroduced later and a few parts of the stream
will progressively be moved overthere. It will more or less contain
only what we need in an embryonic session.
Sample fetch functions and converters will have to change a bit so
that they'll use an L5 (session) instead of what's currently called
"L4" which is in fact L6 for now.
Once all changes are completed, we should see approximately this :
L7 - http_txn
L6 - stream
L5 - session
L4 - connection | applet
There will be at most one http_txn per stream, and a same session will
possibly be referenced by multiple streams. A connection will point to
a session and to a stream. The session will hold all the information
we need to keep even when we don't yet have a stream.
Some more cleanup is needed because some code was already far from
being clean. The server queue management still refers to sessions at
many places while comments talk about connections. This will have to
be cleaned up once we have a server-side connection pool manager.
Stream flags "SN_*" still need to be renamed, it doesn't seem like
any of them will need to move to the session.
2015-04-02 22:22:06 +00:00
|
|
|
void http_perform_server_redirect(struct stream *s, struct stream_interface *si);
|
|
|
|
void http_return_srv_error(struct stream *s, struct stream_interface *si);
|
2018-09-07 16:01:03 +00:00
|
|
|
void http_capture_bad_message(struct proxy *proxy, struct stream *s,
|
2012-03-09 12:39:23 +00:00
|
|
|
struct http_msg *msg,
|
2017-09-21 07:30:46 +00:00
|
|
|
enum h1_state state, struct proxy *other_end);
|
2012-04-26 13:11:51 +00:00
|
|
|
unsigned int http_get_hdr(const struct http_msg *msg, const char *hname, int hlen,
|
2011-12-16 20:35:50 +00:00
|
|
|
struct hdr_idx *idx, int occ,
|
2018-07-13 08:54:26 +00:00
|
|
|
struct hdr_ctx *ctx, char **vptr, size_t *vlen);
|
2018-09-10 15:45:34 +00:00
|
|
|
char *http_txn_get_path(const struct http_txn *txn);
|
2006-06-26 00:48:02 +00:00
|
|
|
|
2015-04-03 21:46:31 +00:00
|
|
|
struct http_txn *http_alloc_txn(struct stream *s);
|
REORG/MAJOR: session: rename the "session" entity to "stream"
With HTTP/2, we'll have to support multiplexed streams. A stream is in
fact the largest part of what we currently call a session, it has buffers,
logs, etc.
In order to catch any error, this commit removes any reference to the
struct session and tries to rename most "session" occurrences in function
names to "stream" and "sess" to "strm" when that's related to a session.
The files stream.{c,h} were added and session.{c,h} removed.
The session will be reintroduced later and a few parts of the stream
will progressively be moved overthere. It will more or less contain
only what we need in an embryonic session.
Sample fetch functions and converters will have to change a bit so
that they'll use an L5 (session) instead of what's currently called
"L4" which is in fact L6 for now.
Once all changes are completed, we should see approximately this :
L7 - http_txn
L6 - stream
L5 - session
L4 - connection | applet
There will be at most one http_txn per stream, and a same session will
possibly be referenced by multiple streams. A connection will point to
a session and to a stream. The session will hold all the information
we need to keep even when we don't yet have a stream.
Some more cleanup is needed because some code was already far from
being clean. The server queue management still refers to sessions at
many places while comments talk about connections. This will have to
be cleaned up once we have a server-side connection pool manager.
Stream flags "SN_*" still need to be renamed, it doesn't seem like
any of them will need to move to the session.
2015-04-02 22:22:06 +00:00
|
|
|
void http_init_txn(struct stream *s);
|
|
|
|
void http_end_txn(struct stream *s);
|
|
|
|
void http_reset_txn(struct stream *s);
|
MAJOR: filters: Add filters support
This patch adds the support of filters in HAProxy. The main idea is to have a
way to "easely" extend HAProxy by adding some "modules", called filters, that
will be able to change HAProxy behavior in a programmatic way.
To do so, many entry points has been added in code to let filters to hook up to
different steps of the processing. A filter must define a flt_ops sutrctures
(see include/types/filters.h for details). This structure contains all available
callbacks that a filter can define:
struct flt_ops {
/*
* Callbacks to manage the filter lifecycle
*/
int (*init) (struct proxy *p);
void (*deinit)(struct proxy *p);
int (*check) (struct proxy *p);
/*
* Stream callbacks
*/
void (*stream_start) (struct stream *s);
void (*stream_accept) (struct stream *s);
void (*session_establish)(struct stream *s);
void (*stream_stop) (struct stream *s);
/*
* HTTP callbacks
*/
int (*http_start) (struct stream *s, struct http_msg *msg);
int (*http_start_body) (struct stream *s, struct http_msg *msg);
int (*http_start_chunk) (struct stream *s, struct http_msg *msg);
int (*http_data) (struct stream *s, struct http_msg *msg);
int (*http_last_chunk) (struct stream *s, struct http_msg *msg);
int (*http_end_chunk) (struct stream *s, struct http_msg *msg);
int (*http_chunk_trailers)(struct stream *s, struct http_msg *msg);
int (*http_end_body) (struct stream *s, struct http_msg *msg);
void (*http_end) (struct stream *s, struct http_msg *msg);
void (*http_reset) (struct stream *s, struct http_msg *msg);
int (*http_pre_process) (struct stream *s, struct http_msg *msg);
int (*http_post_process) (struct stream *s, struct http_msg *msg);
void (*http_reply) (struct stream *s, short status,
const struct chunk *msg);
};
To declare and use a filter, in the configuration, the "filter" keyword must be
used in a listener/frontend section:
frontend test
...
filter <FILTER-NAME> [OPTIONS...]
The filter referenced by the <FILTER-NAME> must declare a configuration parser
on its own name to fill flt_ops and filter_conf field in the proxy's
structure. An exemple will be provided later to make it perfectly clear.
For now, filters cannot be used in backend section. But this is only a matter of
time. Documentation will also be added later. This is the first commit of a long
list about filters.
It is possible to have several filters on the same listener/frontend. These
filters are stored in an array of at most MAX_FILTERS elements (define in
include/types/filters.h). Again, this will be replaced later by a list of
filters.
The filter API has been highly refactored. Main changes are:
* Now, HA supports an infinite number of filters per proxy. To do so, filters
are stored in list.
* Because filters are stored in list, filters state has been moved from the
channel structure to the filter structure. This is cleaner because there is no
more info about filters in channel structure.
* It is possible to defined filters on backends only. For such filters,
stream_start/stream_stop callbacks are not called. Of course, it is possible
to mix frontend and backend filters.
* Now, TCP streams are also filtered. All callbacks without the 'http_' prefix
are called for all kind of streams. In addition, 2 new callbacks were added to
filter data exchanged through a TCP stream:
- tcp_data: it is called when new data are available or when old unprocessed
data are still waiting.
- tcp_forward_data: it is called when some data can be consumed.
* New callbacks attached to channel were added:
- channel_start_analyze: it is called when a filter is ready to process data
exchanged through a channel. 2 new analyzers (a frontend and a backend)
are attached to channels to call this callback. For a frontend filter, it
is called before any other analyzer. For a backend filter, it is called
when a backend is attached to a stream. So some processing cannot be
filtered in that case.
- channel_analyze: it is called before each analyzer attached to a channel,
expects analyzers responsible for data sending.
- channel_end_analyze: it is called when all other analyzers have finished
their processing. A new analyzers is attached to channels to call this
callback. For a TCP stream, this is always the last one called. For a HTTP
one, the callback is called when a request/response ends, so it is called
one time for each request/response.
* 'session_established' callback has been removed. Everything that is done in
this callback can be handled by 'channel_start_analyze' on the response
channel.
* 'http_pre_process' and 'http_post_process' callbacks have been replaced by
'channel_analyze'.
* 'http_start' callback has been replaced by 'http_headers'. This new one is
called just before headers sending and parsing of the body.
* 'http_end' callback has been replaced by 'channel_end_analyze'.
* It is possible to set a forwarder for TCP channels. It was already possible to
do it for HTTP ones.
* Forwarders can partially consumed forwardable data. For this reason a new
HTTP message state was added before HTTP_MSG_DONE : HTTP_MSG_ENDING.
Now all filters can define corresponding callbacks (http_forward_data
and tcp_forward_data). Each filter owns 2 offsets relative to buf->p, next and
forward, to track, respectively, input data already parsed but not forwarded yet
by the filter and parsed data considered as forwarded by the filter. A any time,
we have the warranty that a filter cannot parse or forward more input than
previous ones. And, of course, it cannot forward more input than it has
parsed. 2 macros has been added to retrieve these offets: FLT_NXT and FLT_FWD.
In addition, 2 functions has been added to change the 'next size' and the
'forward size' of a filter. When a filter parses input data, it can alter these
data, so the size of these data can vary. This action has an effet on all
previous filters that must be handled. To do so, the function
'filter_change_next_size' must be called, passing the size variation. In the
same spirit, if a filter alter forwarded data, it must call the function
'filter_change_forward_size'. 'filter_change_next_size' can be called in
'http_data' and 'tcp_data' callbacks and only these ones. And
'filter_change_forward_size' can be called in 'http_forward_data' and
'tcp_forward_data' callbacks and only these ones. The data changes are the
filter responsability, but with some limitation. It must not change already
parsed/forwarded data or data that previous filters have not parsed/forwarded
yet.
Because filters can be used on backends, when we the backend is set for a
stream, we add filters defined for this backend in the filter list of the
stream. But we must only do that when the backend and the frontend of the stream
are not the same. Else same filters are added a second time leading to undefined
behavior.
The HTTP compression code had to be moved.
So it simplifies http_response_forward_body function. To do so, the way the data
are forwarded has changed. Now, a filter (and only one) can forward data. In a
commit to come, this limitation will be removed to let all filters take part to
data forwarding. There are 2 new functions that filters should use to deal with
this feature:
* flt_set_http_data_forwarder: This function sets the filter (using its id)
that will forward data for the specified HTTP message. It is possible if it
was not already set by another filter _AND_ if no data was yet forwarded
(msg->msg_state <= HTTP_MSG_BODY). It returns -1 if an error occurs.
* flt_http_data_forwarder: This function returns the filter id that will
forward data for the specified HTTP message. If there is no forwarder set, it
returns -1.
When an HTTP data forwarder is set for the response, the HTTP compression is
disabled. Of course, this is not definitive.
2015-04-30 09:48:27 +00:00
|
|
|
void http_end_txn_clean_session(struct stream *s);
|
REORG/MAJOR: session: rename the "session" entity to "stream"
With HTTP/2, we'll have to support multiplexed streams. A stream is in
fact the largest part of what we currently call a session, it has buffers,
logs, etc.
In order to catch any error, this commit removes any reference to the
struct session and tries to rename most "session" occurrences in function
names to "stream" and "sess" to "strm" when that's related to a session.
The files stream.{c,h} were added and session.{c,h} removed.
The session will be reintroduced later and a few parts of the stream
will progressively be moved overthere. It will more or less contain
only what we need in an embryonic session.
Sample fetch functions and converters will have to change a bit so
that they'll use an L5 (session) instead of what's currently called
"L4" which is in fact L6 for now.
Once all changes are completed, we should see approximately this :
L7 - http_txn
L6 - stream
L5 - session
L4 - connection | applet
There will be at most one http_txn per stream, and a same session will
possibly be referenced by multiple streams. A connection will point to
a session and to a stream. The session will hold all the information
we need to keep even when we don't yet have a stream.
Some more cleanup is needed because some code was already far from
being clean. The server queue management still refers to sessions at
many places while comments talk about connections. This will have to
be cleaned up once we have a server-side connection pool manager.
Stream flags "SN_*" still need to be renamed, it doesn't seem like
any of them will need to move to the session.
2015-04-02 22:22:06 +00:00
|
|
|
void http_adjust_conn_mode(struct stream *s, struct http_txn *txn, struct http_msg *msg);
|
2009-12-22 14:03:09 +00:00
|
|
|
|
2015-08-04 17:35:46 +00:00
|
|
|
struct act_rule *parse_http_req_cond(const char **args, const char *file, int linenum, struct proxy *proxy);
|
|
|
|
struct act_rule *parse_http_res_cond(const char **args, const char *file, int linenum, struct proxy *proxy);
|
2011-01-06 16:51:27 +00:00
|
|
|
void free_http_req_rules(struct list *r);
|
2014-06-16 18:05:59 +00:00
|
|
|
void free_http_res_rules(struct list *r);
|
2018-07-13 09:56:34 +00:00
|
|
|
void http_reply_and_close(struct stream *s, short status, struct buffer *msg);
|
|
|
|
struct buffer *http_error_message(struct stream *s);
|
2013-11-29 11:15:45 +00:00
|
|
|
struct redirect_rule *http_parse_redirect_rule(const char *file, int linenum, struct proxy *curproxy,
|
2015-05-28 13:26:58 +00:00
|
|
|
const char **args, char **errmsg, int use_fmt, int dir);
|
2015-05-11 13:42:45 +00:00
|
|
|
int smp_fetch_cookie(const struct arg *args, struct sample *smp, const char *kw, void *private);
|
|
|
|
int smp_fetch_base32(const struct arg *args, struct sample *smp, const char *kw, void *private);
|
2011-01-06 16:51:27 +00:00
|
|
|
|
2015-08-19 07:01:53 +00:00
|
|
|
struct action_kw *action_http_req_custom(const char *kw);
|
|
|
|
struct action_kw *action_http_res_custom(const char *kw);
|
2014-12-08 18:50:43 +00:00
|
|
|
int val_hdr(struct arg *arg, char **err_msg);
|
MEDIUM: http: register http-request and http-response keywords
The http_(res|req)_keywords_register() functions allow to register
new keywords.
You need to declare a keyword list:
struct http_req_action_kw_list test_kws = {
.scope = "testscope",
.kw = {
{ "test", parse_test },
{ NULL, NULL },
}
};
and a parsing function:
int parse_test(const char **args, int *cur_arg, struct proxy *px, struct http_req_rule *rule, char **err)
{
rule->action = HTTP_REQ_ACT_CUSTOM_STOP;
rule->action_ptr = action_function;
return 0;
}
http_req_keywords_register(&test_kws);
The HTTP_REQ_ACT_CUSTOM_STOP action stops evaluation of rules after
your rule, HTTP_REQ_ACT_CUSTOM_CONT permits the evaluation of rules
after your rule.
2014-04-24 12:38:37 +00:00
|
|
|
|
2015-09-18 16:11:16 +00:00
|
|
|
int smp_prefetch_http(struct proxy *px, struct stream *s, unsigned int opt,
|
|
|
|
const struct arg *args, struct sample *smp, int req_vol);
|
|
|
|
|
2015-11-03 22:31:35 +00:00
|
|
|
enum act_return http_action_req_capture_by_id(struct act_rule *rule, struct proxy *px,
|
|
|
|
struct session *sess, struct stream *s, int flags);
|
|
|
|
enum act_return http_action_res_capture_by_id(struct act_rule *rule, struct proxy *px,
|
|
|
|
struct session *sess, struct stream *s, int flags);
|
|
|
|
|
2015-12-09 13:59:38 +00:00
|
|
|
int parse_qvalue(const char *qvalue, const char **end);
|
|
|
|
|
2015-09-18 16:11:16 +00:00
|
|
|
/* Note: these functions *do* modify the sample. Even in case of success, at
|
|
|
|
* least the type and uint value are modified.
|
|
|
|
*/
|
|
|
|
#define CHECK_HTTP_MESSAGE_FIRST() \
|
|
|
|
do { int r = smp_prefetch_http(smp->px, smp->strm, smp->opt, args, smp, 1); if (r <= 0) return r; } while (0)
|
|
|
|
|
|
|
|
#define CHECK_HTTP_MESSAGE_FIRST_PERM() \
|
|
|
|
do { int r = smp_prefetch_http(smp->px, smp->strm, smp->opt, args, smp, 0); if (r <= 0) return r; } while (0)
|
|
|
|
|
2015-08-19 07:01:53 +00:00
|
|
|
static inline void http_req_keywords_register(struct action_kw_list *kw_list)
|
MEDIUM: http: register http-request and http-response keywords
The http_(res|req)_keywords_register() functions allow to register
new keywords.
You need to declare a keyword list:
struct http_req_action_kw_list test_kws = {
.scope = "testscope",
.kw = {
{ "test", parse_test },
{ NULL, NULL },
}
};
and a parsing function:
int parse_test(const char **args, int *cur_arg, struct proxy *px, struct http_req_rule *rule, char **err)
{
rule->action = HTTP_REQ_ACT_CUSTOM_STOP;
rule->action_ptr = action_function;
return 0;
}
http_req_keywords_register(&test_kws);
The HTTP_REQ_ACT_CUSTOM_STOP action stops evaluation of rules after
your rule, HTTP_REQ_ACT_CUSTOM_CONT permits the evaluation of rules
after your rule.
2014-04-24 12:38:37 +00:00
|
|
|
{
|
|
|
|
LIST_ADDQ(&http_req_keywords.list, &kw_list->list);
|
|
|
|
}
|
|
|
|
|
2015-08-19 07:01:53 +00:00
|
|
|
static inline void http_res_keywords_register(struct action_kw_list *kw_list)
|
MEDIUM: http: register http-request and http-response keywords
The http_(res|req)_keywords_register() functions allow to register
new keywords.
You need to declare a keyword list:
struct http_req_action_kw_list test_kws = {
.scope = "testscope",
.kw = {
{ "test", parse_test },
{ NULL, NULL },
}
};
and a parsing function:
int parse_test(const char **args, int *cur_arg, struct proxy *px, struct http_req_rule *rule, char **err)
{
rule->action = HTTP_REQ_ACT_CUSTOM_STOP;
rule->action_ptr = action_function;
return 0;
}
http_req_keywords_register(&test_kws);
The HTTP_REQ_ACT_CUSTOM_STOP action stops evaluation of rules after
your rule, HTTP_REQ_ACT_CUSTOM_CONT permits the evaluation of rules
after your rule.
2014-04-24 12:38:37 +00:00
|
|
|
{
|
|
|
|
LIST_ADDQ(&http_res_keywords.list, &kw_list->list);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-11-29 17:12:29 +00:00
|
|
|
/* to be used when contents change in an HTTP message */
|
|
|
|
#define http_msg_move_end(msg, bytes) do { \
|
|
|
|
unsigned int _bytes = (bytes); \
|
2012-03-05 10:17:50 +00:00
|
|
|
(msg)->next += (_bytes); \
|
2009-11-29 17:12:29 +00:00
|
|
|
(msg)->sov += (_bytes); \
|
|
|
|
(msg)->eoh += (_bytes); \
|
|
|
|
} while (0)
|
|
|
|
|
2014-04-17 18:08:17 +00:00
|
|
|
|
2014-04-17 18:18:08 +00:00
|
|
|
/* Return the amount of bytes that need to be rewound before buf->p to access
|
|
|
|
* the current message's headers. The purpose is to be able to easily fetch
|
|
|
|
* the message's beginning before headers are forwarded, as well as after.
|
2014-04-17 19:14:47 +00:00
|
|
|
* The principle is that msg->eoh and msg->eol are immutable while msg->sov
|
|
|
|
* equals the sum of the two before forwarding and is zero after forwarding,
|
|
|
|
* so the difference cancels the rewinding.
|
2014-04-17 18:18:08 +00:00
|
|
|
*/
|
|
|
|
static inline int http_hdr_rewind(const struct http_msg *msg)
|
|
|
|
{
|
2014-04-17 19:14:47 +00:00
|
|
|
return msg->eoh + msg->eol - msg->sov;
|
2014-04-17 18:18:08 +00:00
|
|
|
}
|
|
|
|
|
2014-04-17 18:24:24 +00:00
|
|
|
/* Return the amount of bytes that need to be rewound before buf->p to access
|
|
|
|
* the current message's URI. The purpose is to be able to easily fetch
|
|
|
|
* the message's beginning before headers are forwarded, as well as after.
|
|
|
|
*/
|
|
|
|
static inline int http_uri_rewind(const struct http_msg *msg)
|
|
|
|
{
|
|
|
|
return http_hdr_rewind(msg) - msg->sl.rq.u;
|
|
|
|
}
|
|
|
|
|
2014-04-17 18:31:44 +00:00
|
|
|
/* Return the amount of bytes that need to be rewound before buf->p to access
|
|
|
|
* the current message's BODY. The purpose is to be able to easily fetch
|
|
|
|
* the message's beginning before headers are forwarded, as well as after.
|
|
|
|
*/
|
|
|
|
static inline int http_body_rewind(const struct http_msg *msg)
|
|
|
|
{
|
|
|
|
return http_hdr_rewind(msg) - msg->eoh - msg->eol;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Return the amount of bytes that need to be rewound before buf->p to access
|
|
|
|
* the current message's DATA. The difference with the function above is that
|
|
|
|
* if a chunk is present and has already been parsed, its size is skipped so
|
|
|
|
* that the byte pointed to is the first byte of actual data. The function is
|
|
|
|
* safe for use in state HTTP_MSG_DATA regardless of whether the headers were
|
|
|
|
* already forwarded or not.
|
|
|
|
*/
|
|
|
|
static inline int http_data_rewind(const struct http_msg *msg)
|
|
|
|
{
|
|
|
|
return http_body_rewind(msg) - msg->sol;
|
|
|
|
}
|
|
|
|
|
2014-04-17 18:08:17 +00:00
|
|
|
/* Return the maximum amount of bytes that may be read after the beginning of
|
|
|
|
* the message body, according to the advertised length. The function is safe
|
|
|
|
* for use between HTTP_MSG_BODY and HTTP_MSG_DATA regardless of whether the
|
|
|
|
* headers were already forwarded or not.
|
|
|
|
*/
|
|
|
|
static inline int http_body_bytes(const struct http_msg *msg)
|
|
|
|
{
|
|
|
|
int len;
|
|
|
|
|
2018-06-15 14:42:02 +00:00
|
|
|
len = ci_data(msg->chn) - msg->sov - msg->sol;
|
2014-04-17 18:08:17 +00:00
|
|
|
if (len > msg->body_len)
|
|
|
|
len = msg->body_len;
|
|
|
|
return len;
|
|
|
|
}
|
|
|
|
|
2006-06-26 00:48:02 +00:00
|
|
|
#endif /* _PROTO_PROTO_HTTP_H */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Local variables:
|
|
|
|
* c-indent-level: 8
|
|
|
|
* c-basic-offset: 8
|
|
|
|
* End:
|
|
|
|
*/
|