MEDIUM: HTTP compression (zlib library support)

This commit introduces HTTP compression using the zlib library.

http_response_forward_body has been modified to call the compression
functions.

This feature includes 3 algorithms: identity, gzip and deflate:

  * identity: this is mostly for debugging, and it was useful for
  developping the compression feature. With Content-Length in input, it
  is making each chunk with the data available in the current buffer.
  With chunks in input, it is rechunking, the output chunks will be
  bigger or smaller depending of the size of the input chunk and the
  size of the buffer. Identity does not apply any change on data.

  * gzip: same as identity, but applying a gzip compression. The data
  are deflated using the Z_NO_FLUSH flag in zlib. When there is no more
  data in the input buffer, it flushes the data in the output buffer
  (Z_SYNC_FLUSH). At the end of data, when it receives the last chunk in
  input, or when there is no more data to read, it writes the end of
  data with Z_FINISH and the ending chunk.

  * deflate: same as gzip, but with deflate algorithm and zlib format.
  Note that this algorithm has ambiguous support on many browsers and
  no support at all from recent ones. It is strongly recommended not
  to use it for anything else than experimentation.

You can't choose the compression ratio at the moment, it will be set to
Z_BEST_SPEED (1), as tests have shown very little benefit in terms of
compression ration when going above for HTML contents, at the cost of
a massive CPU impact.

Compression will be activated depending of the Accept-Encoding request
header. With identity, it does not take care of that header.

To build HAProxy with zlib support, use USE_ZLIB=1 in the make
parameters.

This work was initially started by David Du Colombier at Exceliance.
diff --git a/include/proto/compression.h b/include/proto/compression.h
new file mode 100644
index 0000000..6f1a26a
--- /dev/null
+++ b/include/proto/compression.h
@@ -0,0 +1,66 @@
+/*
+ * include/proto/compression.h
+ * This file defines function prototypes for compression.
+ *
+ * Copyright 2012 (C) Exceliance, David Du Colombier <dducolombier@exceliance.fr>
+ *                                William Lallemand <wlallemand@exceliance.fr>
+ *
+ * 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_COMP_H
+#define _PROTO_COMP_H
+
+#include <types/compression.h>
+
+int comp_append_type(struct comp *comp, const char *type);
+int comp_append_algo(struct comp *comp, const char *algo);
+
+int http_emit_chunk_size(char *out, unsigned int chksz, int add_crlf);
+int http_compression_buffer_init(struct session *s, struct buffer *in, struct buffer *out);
+int http_compression_buffer_add_data(struct session *s, struct buffer *in, struct buffer *out);
+int http_compression_buffer_end(struct session *s, struct buffer **in, struct buffer **out, int end);
+
+int identity_init(void *v, int level);
+int identity_add_data(void *v, const char *in_data, int in_len, char *out_data, int out_len);
+int identity_flush(void *comp_ctx, struct buffer *out, int flag);
+int identity_reset(void *comp_ctx);
+int identity_end(void *comp_ctx);
+
+
+#ifdef USE_ZLIB
+
+int deflate_init(void *comp_ctx, int level);
+int deflate_add_data(void *v, const char *in_data, int in_len, char *out_data, int out_len);
+int deflate_flush(void *comp_ctx, struct buffer *out, int flag);
+int deflate_reset(void *comp_ctx);
+int deflate_end(void *comp_ctx);
+
+int gzip_init(void *comp_ctx, int level);
+int gzip_add_data(void *v, const char *in_data, int in_len, char *out_data, int out_len);
+int gzip_flush(void *comp_ctx, struct buffer *out, int flag);
+int gzip_reset(void *comp_ctx);
+int gzip_end(void *comp_ctx);
+
+#endif /* USE_ZLIB */
+
+#endif /* _PROTO_COMP_H */
+
+/*
+ * Local variables:
+ *  c-indent-level: 8
+ *  c-basic-offset: 8
+ * End:
+ */