Workaround for webservers that lie about Content-Encoding: Tor now tries to autodetect compressed directories and compression itself. (resolves bug 65)

svn:r3374
This commit is contained in:
Nick Mathewson
2005-01-19 22:40:33 +00:00
parent e0bf597665
commit 69fa5be7b6
3 changed files with 95 additions and 11 deletions
+16
View File
@@ -134,6 +134,7 @@ tor_gzip_compress(char **out, size_t *out_len,
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 @@ tor_gzip_uncompress(char **out, size_t *out_len,
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;
}
}
+5 -1
View File
@@ -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 @@ tor_gzip_uncompress(char **out, size_t *out_len,
int is_gzip_supported(void);
int detect_compression_method(const char *in, size_t in_len);
#endif