[or-cvs] Workaround for webservers that lie about Content-Encoding: ...

Nick Mathewson nickm at seul.org
Wed Jan 19 22:40:35 UTC 2005


Update of /home/or/cvsroot/tor/src/common
In directory moria.mit.edu:/tmp/cvs-serv26308/src/common

Modified Files:
	torgzip.c torgzip.h 
Log Message:
Workaround for webservers that lie about Content-Encoding: Tor now tries to autodetect compressed directories and compression itself. (resolves bug 65)

Index: torgzip.c
===================================================================
RCS file: /home/or/cvsroot/tor/src/common/torgzip.c,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -d -r1.9 -r1.10
--- torgzip.c	29 Nov 2004 22:25:28 -0000	1.9
+++ torgzip.c	19 Jan 2005 22:40:32 -0000	1.10
@@ -134,6 +134,7 @@
   return -1;
 }
 
+/* DOCDOC -- sets *out to NULL on failure. */
 int
 tor_gzip_uncompress(char **out, size_t *out_len,
                     const char *in, size_t in_len,
@@ -224,3 +225,18 @@
   return -1;
 }
 
+/** Try to tell whether the <b>in_len</b>-byte string in <b>in</b> is likely
+ * to be compressed or not.  If it is, return the likeliest compression method.
+ * Otherwise, return 0.
+ */
+int detect_compression_method(const char *in, size_t in_len)
+{
+  if (in_len > 2 && in[0] == 0x1f && in[1] == 0x8b) {
+    return GZIP_METHOD;
+  } else if (in_len > 2 && (in[0] & 0x0f) == 8 &&
+             get_uint16(in) % 31 == 0) {
+    return ZLIB_METHOD;
+  } else {
+    return 0;
+  }
+}

Index: torgzip.h
===================================================================
RCS file: /home/or/cvsroot/tor/src/common/torgzip.h,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- torgzip.h	29 Nov 2004 22:25:28 -0000	1.4
+++ torgzip.h	19 Jan 2005 22:40:32 -0000	1.5
@@ -11,7 +11,9 @@
 #define __TORGZIP_H
 #define TORGZIP_H_ID "$Id$"
 
-typedef enum { GZIP_METHOD=1, ZLIB_METHOD=2 } compress_method_t;
+typedef enum {
+  GZIP_METHOD=1, ZLIB_METHOD=2, UNKNOWN_METHOD=3
+} compress_method_t;
 
 int
 tor_gzip_compress(char **out, size_t *out_len,
@@ -24,4 +26,6 @@
 
 int is_gzip_supported(void);
 
+int detect_compression_method(const char *in, size_t in_len);
+
 #endif



More information about the tor-commits mailing list