From 902522fbdf1ec0f2d526a2ad50b34d420fad26a1 Mon Sep 17 00:00:00 2001
From: Witold Filipczyk <witekfl@poczta.onet.pl>
Date: Mon, 18 Feb 2008 14:30:49 +0100
Subject: [PATCH] content encoding: New function accept_encoding_header.

---
 src/encoding/encoding.c  | 27 +++++++++++++++++++++++++++
 src/encoding/encoding.h  |  2 ++
 src/protocol/http/http.c | 20 ++------------------
 3 files changed, 31 insertions(+), 18 deletions(-)

diff --git a/src/encoding/encoding.c b/src/encoding/encoding.c
index 4d8c2d35b..99f75cc6e 100644
--- a/src/encoding/encoding.c
+++ b/src/encoding/encoding.c
@@ -344,3 +344,30 @@ read_encoded_file(struct string *filename, struct string *page)
 	close(fd);
 	return state;
 }
+
+void
+accept_encoding_header(struct string *header)
+{
+#if defined(CONFIG_GZIP) || defined(CONFIG_BZIP2) || defined(CONFIG_LZMA)
+	int comma = 0;
+
+	add_to_string(header, "Accept-Encoding: ");
+
+#ifdef CONFIG_BZIP2
+	add_to_string(header, "bzip2");
+	comma = 1;
+#endif
+
+#ifdef CONFIG_GZIP
+	if (comma) add_to_string(header, ", ");
+	add_to_string(header, "deflate, gzip");
+	comma = 1;
+#endif
+
+#ifdef CONFIG_LZMA
+	if (comma) add_to_string(header, ", ");
+	add_to_string(header, "lzma");
+#endif
+	add_crlf_to_string(header);
+#endif
+}
diff --git a/src/encoding/encoding.h b/src/encoding/encoding.h
index 00b4ab2cf..26688e566 100644
--- a/src/encoding/encoding.h
+++ b/src/encoding/encoding.h
@@ -45,4 +45,6 @@ read_file(struct stream_encoded *stream, int readsize, struct string *page);
 /* Reads the file with the given @filename into the string @source. */
 enum connection_state read_encoded_file(struct string *filename, struct string *source);
 
+void accept_encoding_header(struct string *header);
+
 #endif
diff --git a/src/protocol/http/http.c b/src/protocol/http/http.c
index 82b088183..fc94c9e64 100644
--- a/src/protocol/http/http.c
+++ b/src/protocol/http/http.c
@@ -23,6 +23,7 @@
 #include "cache/cache.h"
 #include "config/options.h"
 #include "cookies/cookies.h"
+#include "encoding/encoding.h"
 #include "intl/charsets.h"
 #include "intl/gettext/libintl.h"
 #include "main/module.h"
@@ -745,24 +746,7 @@ http_send_header(struct socket *socket)
 	add_to_string(&header, "Accept: */*");
 	add_crlf_to_string(&header);
 
-	/* TODO: Make this encoding.c function. */
-#if defined(CONFIG_GZIP) || defined(CONFIG_BZIP2)
-	add_to_string(&header, "Accept-Encoding: ");
-
-#ifdef CONFIG_BZIP2
-	add_to_string(&header, "bzip2");
-#endif
-
-#ifdef CONFIG_GZIP
-
-#ifdef CONFIG_BZIP2
-	add_to_string(&header, ", ");
-#endif
-
-	add_to_string(&header, "deflate, gzip");
-#endif
-	add_crlf_to_string(&header);
-#endif
+	accept_encoding_header(&header);
 
 	if (!accept_charset) {
 		init_accept_charset();