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.
diff --git a/include/proto/filters.h b/include/proto/filters.h
new file mode 100644
index 0000000..d860424
--- /dev/null
+++ b/include/proto/filters.h
@@ -0,0 +1,138 @@
+/*
+ * include/proto/filters.h
+ * This file defines function prototypes for stream filters management.
+ *
+ * Copyright (C) 2015 Qualys Inc., Christopher Faulet <cfaulet@qualys.com>
+ *
+ * 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
+ */
+#ifndef _PROTO_FILTERS_H
+#define _PROTO_FILTERS_H
+
+#include <types/channel.h>
+#include <types/filters.h>
+#include <types/proto_http.h>
+#include <types/proxy.h>
+#include <types/stream.h>
+
+#include <proto/channel.h>
+
+/* Useful macros to access per-channel values. It can be safely used inside
+ * filters. */
+#define CHN_IDX(chn)     (((chn)->flags & CF_ISRESP) == CF_ISRESP)
+#define FLT_NXT(flt, chn) ((flt)->next[CHN_IDX(chn)])
+#define FLT_FWD(flt, chn) ((flt)->fwd[CHN_IDX(chn)])
+
+extern struct pool_head *pool2_filter;
+
+int  flt_init(struct proxy *p);
+void flt_deinit(struct proxy *p);
+int  flt_check(struct proxy *p);
+
+int  flt_stream_start(struct stream *s);
+void flt_stream_stop(struct stream *s);
+
+int  flt_http_headers(struct stream *s, struct http_msg *msg);
+int  flt_http_start_chunk(struct stream *s, struct http_msg *msg);
+int  flt_http_data(struct stream *s, struct http_msg *msg);
+int  flt_http_last_chunk(struct stream *s, struct http_msg *msg);
+int  flt_http_end_chunk(struct stream *s, struct http_msg *msg);
+int  flt_http_chunk_trailers(struct stream *s, struct http_msg *msg);
+int  flt_http_end(struct stream *s, struct http_msg *msg);
+void flt_http_reset(struct stream *s, struct http_msg *msg);
+
+void flt_http_reply(struct stream *s, short status, const struct chunk *msg);
+int  flt_http_forward_data(struct stream *s, struct http_msg *msg, unsigned int len);
+
+int  flt_start_analyze(struct stream *s, struct channel *chn, unsigned int an_bit);
+int  flt_analyze(struct stream *s, struct channel *chn, unsigned int an_bit);
+int  flt_end_analyze(struct stream *s, struct channel *chn, unsigned int an_bit);
+
+int  flt_xfer_data(struct stream *s, struct channel *chn, unsigned int an_bit);
+
+void           flt_register_keywords(struct flt_kw_list *kwl);
+struct flt_kw *flt_find_kw(const char *kw);
+void           flt_dump_kws(char **out);
+
+static inline void
+flt_set_forward_data(struct filter *filter, struct channel *chn)
+{
+	filter->flags[CHN_IDX(chn)] |= FILTER_FL_FORWARD_DATA;
+}
+
+static inline void
+flt_reset_forward_data(struct filter *filter, struct channel *chn)
+{
+	filter->flags[CHN_IDX(chn)] &= ~FILTER_FL_FORWARD_DATA;
+}
+
+static inline int
+flt_want_forward_data(struct filter *filter, const struct channel *chn)
+{
+	return filter->flags[CHN_IDX(chn)] & FILTER_FL_FORWARD_DATA;
+}
+
+
+/* This function must be called when a filter alter incoming data. It updates
+ * next offset value of all filter's predecessors. Do not call this function
+ * when a filter change the size of incomding data leads to an undefined
+ * behavior.
+ *
+ * This is the filter's responsiblitiy to update data itself. For now, it is
+ * unclear to know how to handle data updates, so we do the minimum here. For
+ * example, if you filter an HTTP message, we must update msg->next and
+ * msg->chunk_len values.
+ */
+static inline void
+flt_change_next_size(struct filter *filter, struct channel *chn, int len)
+{
+	struct stream *s = chn_strm(chn);
+	struct filter *f;
+
+	list_for_each_entry(f, &s->strm_flt.filters, list) {
+		if (f == filter)
+			break;
+		FLT_NXT(f, chn) += len;
+	}
+}
+
+/* This function must be called when a filter alter forwarded data. It updates
+ * offset values (next and forward) of all filters. Do not call this function
+ * when a filter change the size of forwarded data leads to an undefined
+ * behavior.
+ *
+ * This is the filter's responsiblitiy to update data itself. For now, it is
+ * unclear to know how to handle data updates, so we do the minimum here. For
+ * example, if you filter an HTTP message, we must update msg->next and
+ * msg->chunk_len values.
+ */
+static inline void
+flt_change_forward_size(struct filter *filter, struct channel *chn, int len)
+{
+	struct stream *s = chn_strm(chn);
+	struct filter *f;
+	int before = 1;
+
+	list_for_each_entry(f, &s->strm_flt.filters, list) {
+		if (f == filter)
+			before = 0;
+		if (before)
+			FLT_FWD(f, chn) += len;
+		FLT_NXT(f, chn) += len;
+	}
+}
+
+
+#endif /* _PROTO_FILTERS_H */
diff --git a/include/proto/proto_http.h b/include/proto/proto_http.h
index ef564dc..9317a55 100644
--- a/include/proto/proto_http.h
+++ b/include/proto/proto_http.h
@@ -126,6 +126,7 @@
 void http_init_txn(struct stream *s);
 void http_end_txn(struct stream *s);
 void http_reset_txn(struct stream *s);
+void http_end_txn_clean_session(struct stream *s);
 void http_adjust_conn_mode(struct stream *s, struct http_txn *txn, struct http_msg *msg);
 
 struct act_rule *parse_http_req_cond(const char **args, const char *file, int linenum, struct proxy *proxy);
@@ -284,6 +285,7 @@
 	case HTTP_MSG_DATA:        return "MSG_DATA";
 	case HTTP_MSG_CHUNK_CRLF:  return "MSG_CHUNK_CRLF";
 	case HTTP_MSG_TRAILERS:    return "MSG_TRAILERS";
+	case HTTP_MSG_ENDING:      return "MSG_ENDING";
 	case HTTP_MSG_DONE:        return "MSG_DONE";
 	case HTTP_MSG_CLOSING:     return "MSG_CLOSING";
 	case HTTP_MSG_CLOSED:      return "MSG_CLOSED";
diff --git a/include/types/channel.h b/include/types/channel.h
index e95c462..e43e8eb 100644
--- a/include/types/channel.h
+++ b/include/types/channel.h
@@ -157,6 +157,13 @@
 #define AN_RES_STORE_RULES      0x00080000  /* table persistence matching */
 #define AN_RES_HTTP_XFER_BODY   0x00100000  /* forward response body */
 
+#define AN_FLT_START_FE         0x01000000
+#define AN_FLT_START_BE         0x02000000
+#define AN_FLT_END              0x04000000
+#define AN_FLT_XFER_DATA        0x08000000
+
+#define AN_FLT_ALL_FE           0x0d000000
+#define AN_FLT_ALL_BE           0x0e000000
 
 /* Magic value to forward infinite size (TCP, ...), used with ->to_forward */
 #define CHN_INFINITE_FORWARD    MAX_RANGE(unsigned int)
diff --git a/include/types/filters.h b/include/types/filters.h
new file mode 100644
index 0000000..635b2d1
--- /dev/null
+++ b/include/types/filters.h
@@ -0,0 +1,233 @@
+/*
+ * include/types/filteers.h
+ * This file defines everything related to stream filters.
+ *
+ * Copyright (C) 2015 Qualys Inc., Christopher Faulet <cfaulet@qualys.com>
+ *
+ * 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
+ */
+#ifndef _TYPES_FILTERS_H
+#define _TYPES_FILTERS_H
+
+#include <common/config.h>
+#include <common/mini-clist.h>
+
+struct http_msg;
+struct proxy;
+struct stream;
+struct channel;
+struct filter;
+
+/* Descriptor for a "filter" keyword. The ->parse() function returns 0 in case
+ * of success, or a combination of ERR_* flags if an error is encountered. The
+ * function pointer can be NULL if not implemented. The function also has an
+ * access to the current "server" config line. The ->skip value tells the parser
+ * how many words have to be skipped after the keyword. If the function needs to
+ * parse more keywords, it needs to update cur_arg.
+ */
+struct flt_kw {
+	const char *kw;
+	int (*parse)(char **args, int *cur_arg, struct proxy *px,
+		     struct filter *filter, char **err);
+};
+
+/*
+ * A keyword list. It is a NULL-terminated array of keywords. It embeds a struct
+ * list in order to be linked to other lists, allowing it to easily be declared
+ * where it is needed, and linked without duplicating data nor allocating
+ * memory. It is also possible to indicate a scope for the keywords.
+ */
+struct flt_kw_list {
+	const char *scope;
+	struct list list;
+	struct flt_kw kw[VAR_ARRAY];
+};
+
+/*
+ * Filter flags set for a specific filter on channel
+ *
+ *  - FILTER_FL_FORWARD_DATA : When this flag is set, the rest of the data is
+ *                             directly forwarded. For chunk-encoded HTTP
+ *                             messages, this flag is reseted between each
+ *                             chunks.
+ */
+#define FILTER_FL_FORWARD_DATA 0x00000001
+
+
+/*
+ * Callbacks available on a filter:
+ *
+ *  - init                : Initializes the filter for a proxy. Returns a
+ *                          negative value if an error occurs.
+ *  - deinit              : Cleans up what the init function has done.
+ *  - check               : Check the filter config for a proxy. Returns the
+ *                          number of errors encountered.
+ *
+ *
+ *  - stream_start        : Called when a stream is started. This callback will
+ *                          only be called for filters defined on a proxy with
+ *                          the frontend capability.
+ *                          Returns a negative value if an error occurs, any
+ *                          other value otherwise.
+ *  - stream_stop         : Called when a stream is stopped. This callback will
+ *                          only be called for filters defined on a proxy with
+ *                          the frontend capability.
+ *
+ *
+ *  - channel_start_analyze: Called when a filter starts to analyze a channel.
+ *                          Returns a negative value if an error occurs, 0 if
+ *                          it needs to wait, any other value otherwise.
+ *  - channel_analyze     : Called before each analyzer attached to a channel,
+ *                          expects analyzers responsible for data sending.
+ *                          Returns a negative value if an error occurs, 0 if
+ *                          it needs to wait, any other value otherwise.
+ *  - channel_end_analyze : Called when all other analyzers have finished their
+ *                          processing.
+ *                          Returns a negative value if an error occurs, 0 if
+ *                          it needs to wait, any other value otherwise.
+ *
+ *
+ *  - http_headers        : Called just before headers sending and parsing of
+ *                          the body. At this step, headers are fully parsed
+ *                          and the processing on it is finished.
+ *                          Returns a negative value if an error occurs, 0 if
+ *                          it needs to read more data (or to wait for some
+ *                          reason), any other value otherwise.
+ *  - http_start_chunk    : Called when we start to process a new chunk
+ *                          (for chunk-encoded request/response only). At this
+ *                          step, the chunk length is known and non-null.
+ *                          Returns a negative value if an error occurs, 0 if
+ *                          it needs to read more data (or to wait for some
+ *                          reason), any other value otherwise.
+ *  - http_data           : Called when unparsed body data are available.
+ *                          Returns a negative value if an error occurs, else
+ *                          the number of consumed bytes.
+ *  - http_last_chunk     : Called when the last chunk (with a zero length) is
+ *                          received.
+ *                          Returns a negative value if an error occurs, 0 if
+ *                          it needs to read more data (or to wait for some
+ *                          reason), any other value otherwise.
+ *  - http_end_chunk      : Called at the end of a chunk (expect for the last
+ *                          one).
+ *                          Returns a negative value if an error occurs, 0 if
+ *                          it needs to read more data (or to wait for some
+ *                          reason), any other value otherwise.
+ *  - http_chunk_trailers : Called when part of trailer headers of a
+ *                          chunk-encoded request/response are ready to be
+ *                          processed.
+ *                          Returns a negative value if an error occurs, any
+ *                          other value otherwise.
+ *  - http_end            : Called when all the request/response has been
+ *                          processed and all body data has been forwarded.
+ *                          Returns a negative value if an error occurs, 0 if
+ *                          it needs to wait for some reason, any other value
+ *                          otherwise.
+ *  - http_reset          : Called when the HTTP message is reseted. It happens
+ *                          when a 100-continue response is received.
+ *                          Returns nothing.
+ *  - http_reply          : Called when, at any time, HA proxy decides to stop
+ *                          the HTTP message's processing and to send a message
+ *                          to the client (mainly, when an error or a redirect
+ *                          occur).
+ *                          Returns nothing.
+ *  - http_forward_data   : Called when some data can be consumed.
+ *                          Returns a negative value if an error occurs, else
+ *                          the number of forwarded bytes.
+ *  - tcp_data            : Called when unparsed data are available.
+ *                          Returns a negative value if an error occurs, else
+ *                          the number of consumed bytes.
+ *  - tcp_forward_data    : Called when some data can be consumed.
+ *                          Returns a negative value if an error occurs, else
+ *                          or the number of forwarded bytes.
+ */
+struct flt_ops {
+	/*
+	 * Callbacks to manage the filter lifecycle
+	 */
+	int  (*init)  (struct proxy *p, struct filter *f);
+	void (*deinit)(struct proxy *p, struct filter *f);
+	int  (*check) (struct proxy *p, struct filter *f);
+
+	/*
+	 * Stream callbacks
+	 */
+	int  (*stream_start)     (struct stream *s, struct filter *f);
+	void (*stream_stop)      (struct stream *s, struct filter *f);
+
+	/*
+	 * Channel callbacks
+	 */
+	int  (*channel_start_analyze)(struct stream *s, struct filter *f, struct channel *chn);
+	int  (*channel_analyze)      (struct stream *s, struct filter *f, struct channel *chn, unsigned int an_bit);
+	int  (*channel_end_analyze)  (struct stream *s, struct filter *f, struct channel *chn);
+
+	/*
+	 * HTTP callbacks
+	 */
+	int  (*http_headers)       (struct stream *s, struct filter *f, struct http_msg *msg);
+	int  (*http_start_chunk)   (struct stream *s, struct filter *f, struct http_msg *msg);
+	int  (*http_data)          (struct stream *s, struct filter *f, struct http_msg *msg);
+	int  (*http_last_chunk)    (struct stream *s, struct filter *f, struct http_msg *msg);
+	int  (*http_end_chunk)     (struct stream *s, struct filter *f, struct http_msg *msg);
+	int  (*http_chunk_trailers)(struct stream *s, struct filter *f, struct http_msg *msg);
+	int  (*http_end)           (struct stream *s, struct filter *f, struct http_msg *msg);
+	void (*http_reset)         (struct stream *s, struct filter *f, struct http_msg *msg);
+
+	void (*http_reply)         (struct stream *s, struct filter *f, short status,
+				    const struct chunk *msg);
+	int  (*http_forward_data)  (struct stream *s, struct filter *f, struct http_msg *msg,
+				    unsigned int len);
+
+	/*
+	 * TCP callbacks
+	 */
+	int  (*tcp_data)        (struct stream *s, struct filter *f, struct channel *chn);
+	int  (*tcp_forward_data)(struct stream *s, struct filter *f, struct channel *chn,
+				 unsigned int len);
+};
+
+/*
+ * Structure representing the state of a filter. When attached to a proxy, only
+ * <ops> and <conf> field (and optionnaly <id>) are set. All other fields are
+ * used when the filter is attached to a stream.
+ *
+ * 2D-Array fields are used to store info per channel. The first index stands
+ * for the request channel, and the second one for the response channel.
+ * Especially, <next> and <fwd> are offets representing amount of data that the
+ * filter are, respectively, parsed and forwarded on a channel. Filters can
+ * access these values using FLT_NXT and FLT_FWD macros.
+ */
+struct filter {
+	const char     *id;                /* The filter id */
+	struct flt_ops *ops;               /* The filter callbacks */
+	void           *conf;              /* The filter configuration */
+	void           *ctx;               /* The filter context (opaque) */
+	int             is_backend_filter; /* Flag to specify if the filter is a "backend" filter */
+	unsigned int    flags[2];          /* 0: request, 1: response */
+	unsigned int    next[2];           /* Offset, relative to buf->p, to the next byte to parse for a specific channel
+	                                    * 0: request channel, 1: response channel */
+	unsigned int    fwd[2];            /* Offset, relative to buf->p, to the next byte to forward for a specific channel
+	                                    * 0: request channel, 1: response channel */
+	struct list     list;              /* Next filter for the same proxy/stream */
+};
+
+#endif /* _TYPES_FILTERS_H */
+
+/*
+ * Local variables:
+ *  c-indent-level: 8
+ *  c-basic-offset: 8
+ * End:
+ */
diff --git a/include/types/proto_http.h b/include/types/proto_http.h
index e5e9667..c6699bd 100644
--- a/include/types/proto_http.h
+++ b/include/types/proto_http.h
@@ -28,7 +28,7 @@
 #include <common/regex.h>
 
 #include <types/hdr_idx.h>
-#include <types/sample.h>
+#include <types/filters.h>
 
 /* These are the flags that are found in txn->flags */
 
@@ -170,10 +170,11 @@
 	HTTP_MSG_CHUNK_CRLF   = 31, // skipping CRLF after data chunk
 	HTTP_MSG_TRAILERS     = 32, // trailers (post-data entity headers)
 	/* we enter this state when we've received the end of the current message */
-	HTTP_MSG_DONE         = 33, // message end received, waiting for resync or close
-	HTTP_MSG_CLOSING      = 34, // shutdown_w done, not all bytes sent yet
-	HTTP_MSG_CLOSED       = 35, // shutdown_w done, all bytes sent
-	HTTP_MSG_TUNNEL       = 36, // tunneled data after DONE
+	HTTP_MSG_ENDING       = 33, // message end received, wait that the filters end too
+	HTTP_MSG_DONE         = 34, // message end received, waiting for resync or close
+	HTTP_MSG_CLOSING      = 35, // shutdown_w done, not all bytes sent yet
+	HTTP_MSG_CLOSED       = 36, // shutdown_w done, all bytes sent
+	HTTP_MSG_TUNNEL       = 37, // tunneled data after DONE
 } __attribute__((packed));
 
 /*
@@ -194,6 +195,7 @@
  * contents if something needs them during a redispatch.
  */
 #define HTTP_MSGF_WAIT_CONN   0x00000010  /* Wait for connect() to be confirmed before processing body */
+#define HTTP_MSGF_COMPRESSING 0x00000020  /* data compression is in progress */
 
 
 /* Redirect flags */
diff --git a/include/types/proxy.h b/include/types/proxy.h
index e18ae72..71fd35d 100644
--- a/include/types/proxy.h
+++ b/include/types/proxy.h
@@ -38,6 +38,7 @@
 #include <types/acl.h>
 #include <types/backend.h>
 #include <types/counters.h>
+#include <types/filters.h>
 #include <types/freq_ctr.h>
 #include <types/listener.h>
 #include <types/log.h>
@@ -431,6 +432,8 @@
 						 * this backend. If not specified or void, then the backend
 						 * name is used
 						 */
+
+	struct list filters;
 };
 
 struct switching_rule {
diff --git a/include/types/stream.h b/include/types/stream.h
index bba5f43..292e36a 100644
--- a/include/types/stream.h
+++ b/include/types/stream.h
@@ -33,6 +33,7 @@
 
 #include <types/channel.h>
 #include <types/compression.h>
+#include <types/filters.h>
 #include <types/hlua.h>
 #include <types/obj_type.h>
 #include <types/proto_http.h>
@@ -45,7 +46,6 @@
 #include <types/stick_table.h>
 #include <types/vars.h>
 
-
 /* Various Stream Flags, bits values 0x01 to 0x100 (shift 0) */
 #define SF_DIRECT	0x00000001	/* connection made on the server matching the client cookie */
 #define SF_ASSIGNED	0x00000002	/* no need to assign a server to this stream */
@@ -127,6 +127,11 @@
 
 	struct http_txn *txn;           /* current HTTP transaction being processed. Should become a list. */
 
+	struct {
+		struct list    filters;
+		struct filter *current[2];        /* 0: request, 1: response */
+	} strm_flt;
+
 	struct task *task;              /* the task associated with this stream */
 	struct list list;               /* position in global streams list */
 	struct list by_srv;             /* position in server stream list */