Moved Huffman coding out of HTTP/2.
ngx_http_v2_huff_decode.c and ngx_http_v2_huff_encode.c are renamed
to ngx_http_huff_decode.c and ngx_http_huff_encode.c.
diff --git a/auto/modules b/auto/modules
index f5a4597..94867bf 100644
--- a/auto/modules
+++ b/auto/modules
@@ -102,6 +102,11 @@
fi
+ if [ $HTTP_V2 = YES ]; then
+ HTTP_SRCS="$HTTP_SRCS $HTTP_HUFF_SRCS"
+ fi
+
+
# the module order is important
# ngx_http_static_module
# ngx_http_gzip_static_module
@@ -414,8 +419,6 @@
ngx_module_srcs="src/http/v2/ngx_http_v2.c \
src/http/v2/ngx_http_v2_table.c \
src/http/v2/ngx_http_v2_encode.c \
- src/http/v2/ngx_http_v2_huff_decode.c \
- src/http/v2/ngx_http_v2_huff_encode.c \
src/http/v2/ngx_http_v2_module.c"
ngx_module_libs=
ngx_module_link=$HTTP_V2
diff --git a/auto/sources b/auto/sources
index 3dad111..156f797 100644
--- a/auto/sources
+++ b/auto/sources
@@ -255,3 +255,6 @@
HTTP_FILE_CACHE_SRCS=src/http/ngx_http_file_cache.c
+
+HTTP_HUFF_SRCS="src/http/ngx_http_huff_decode.c
+ src/http/ngx_http_huff_encode.c"
diff --git a/src/http/modules/ngx_http_grpc_module.c b/src/http/modules/ngx_http_grpc_module.c
index 6842b7c..864fc4f 100644
--- a/src/http/modules/ngx_http_grpc_module.c
+++ b/src/http/modules/ngx_http_grpc_module.c
@@ -3180,10 +3180,10 @@
ctx->field_rest -= size;
if (ctx->field_huffman) {
- if (ngx_http_v2_huff_decode(&ctx->field_state, p, size,
- &ctx->field_end,
- ctx->field_rest == 0,
- r->connection->log)
+ if (ngx_http_huff_decode(&ctx->field_state, p, size,
+ &ctx->field_end,
+ ctx->field_rest == 0,
+ r->connection->log)
!= NGX_OK)
{
ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
@@ -3289,10 +3289,10 @@
ctx->field_rest -= size;
if (ctx->field_huffman) {
- if (ngx_http_v2_huff_decode(&ctx->field_state, p, size,
- &ctx->field_end,
- ctx->field_rest == 0,
- r->connection->log)
+ if (ngx_http_huff_decode(&ctx->field_state, p, size,
+ &ctx->field_end,
+ ctx->field_rest == 0,
+ r->connection->log)
!= NGX_OK)
{
ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
diff --git a/src/http/ngx_http.h b/src/http/ngx_http.h
index 8b43857..be8b7cd 100644
--- a/src/http/ngx_http.h
+++ b/src/http/ngx_http.h
@@ -167,6 +167,14 @@
#endif
+#if (NGX_HTTP_V2)
+ngx_int_t ngx_http_huff_decode(u_char *state, u_char *src, size_t len,
+ u_char **dst, ngx_uint_t last, ngx_log_t *log);
+size_t ngx_http_huff_encode(u_char *src, size_t len, u_char *dst,
+ ngx_uint_t lower);
+#endif
+
+
extern ngx_module_t ngx_http_module;
extern ngx_str_t ngx_http_html_default_types[];
diff --git a/src/http/v2/ngx_http_v2_huff_decode.c b/src/http/ngx_http_huff_decode.c
similarity index 99%
rename from src/http/v2/ngx_http_v2_huff_decode.c
rename to src/http/ngx_http_huff_decode.c
index 49ca576..14b7b78 100644
--- a/src/http/v2/ngx_http_v2_huff_decode.c
+++ b/src/http/ngx_http_huff_decode.c
@@ -15,14 +15,14 @@
u_char emit;
u_char sym;
u_char ending;
-} ngx_http_v2_huff_decode_code_t;
+} ngx_http_huff_decode_code_t;
-static ngx_inline ngx_int_t ngx_http_v2_huff_decode_bits(u_char *state,
+static ngx_inline ngx_int_t ngx_http_huff_decode_bits(u_char *state,
u_char *ending, ngx_uint_t bits, u_char **dst);
-static ngx_http_v2_huff_decode_code_t ngx_http_v2_huff_decode_codes[256][16] =
+static ngx_http_huff_decode_code_t ngx_http_huff_decode_codes[256][16] =
{
/* 0 */
{
@@ -2640,7 +2640,7 @@
ngx_int_t
-ngx_http_v2_huff_decode(u_char *state, u_char *src, size_t len, u_char **dst,
+ngx_http_huff_decode(u_char *state, u_char *src, size_t len, u_char **dst,
ngx_uint_t last, ngx_log_t *log)
{
u_char *end, ch, ending;
@@ -2653,7 +2653,7 @@
while (src != end) {
ch = *src++;
- if (ngx_http_v2_huff_decode_bits(state, &ending, ch >> 4, dst)
+ if (ngx_http_huff_decode_bits(state, &ending, ch >> 4, dst)
!= NGX_OK)
{
ngx_log_debug2(NGX_LOG_DEBUG_HTTP, log, 0,
@@ -2663,7 +2663,7 @@
return NGX_ERROR;
}
- if (ngx_http_v2_huff_decode_bits(state, &ending, ch & 0xf, dst)
+ if (ngx_http_huff_decode_bits(state, &ending, ch & 0xf, dst)
!= NGX_OK)
{
ngx_log_debug2(NGX_LOG_DEBUG_HTTP, log, 0,
@@ -2692,12 +2692,12 @@
static ngx_inline ngx_int_t
-ngx_http_v2_huff_decode_bits(u_char *state, u_char *ending, ngx_uint_t bits,
+ngx_http_huff_decode_bits(u_char *state, u_char *ending, ngx_uint_t bits,
u_char **dst)
{
- ngx_http_v2_huff_decode_code_t code;
+ ngx_http_huff_decode_code_t code;
- code = ngx_http_v2_huff_decode_codes[*state][bits];
+ code = ngx_http_huff_decode_codes[*state][bits];
if (code.next == *state) {
return NGX_ERROR;
diff --git a/src/http/v2/ngx_http_v2_huff_encode.c b/src/http/ngx_http_huff_encode.c
similarity index 92%
rename from src/http/v2/ngx_http_v2_huff_encode.c
rename to src/http/ngx_http_huff_encode.c
index 3f822cd..c03b153 100644
--- a/src/http/v2/ngx_http_v2_huff_encode.c
+++ b/src/http/ngx_http_huff_encode.c
@@ -14,10 +14,10 @@
typedef struct {
uint32_t code;
uint32_t len;
-} ngx_http_v2_huff_encode_code_t;
+} ngx_http_huff_encode_code_t;
-static ngx_http_v2_huff_encode_code_t ngx_http_v2_huff_encode_table[256] =
+static ngx_http_huff_encode_code_t ngx_http_huff_encode_table[256] =
{
{0x00001ff8, 13}, {0x007fffd8, 23}, {0x0fffffe2, 28}, {0x0fffffe3, 28},
{0x0fffffe4, 28}, {0x0fffffe5, 28}, {0x0fffffe6, 28}, {0x0fffffe7, 28},
@@ -87,7 +87,7 @@
/* same as above, but embeds lowercase transformation */
-static ngx_http_v2_huff_encode_code_t ngx_http_v2_huff_encode_table_lc[256] =
+static ngx_http_huff_encode_code_t ngx_http_huff_encode_table_lc[256] =
{
{0x00001ff8, 13}, {0x007fffd8, 23}, {0x0fffffe2, 28}, {0x0fffffe3, 28},
{0x0fffffe4, 28}, {0x0fffffe5, 28}, {0x0fffffe6, 28}, {0x0fffffe7, 28},
@@ -161,10 +161,10 @@
#if (NGX_HAVE_LITTLE_ENDIAN)
#if (NGX_HAVE_GCC_BSWAP64)
-#define ngx_http_v2_huff_encode_buf(dst, buf) \
+#define ngx_http_huff_encode_buf(dst, buf) \
(*(uint64_t *) (dst) = __builtin_bswap64(buf))
#else
-#define ngx_http_v2_huff_encode_buf(dst, buf) \
+#define ngx_http_huff_encode_buf(dst, buf) \
((dst)[0] = (u_char) ((buf) >> 56), \
(dst)[1] = (u_char) ((buf) >> 48), \
(dst)[2] = (u_char) ((buf) >> 40), \
@@ -176,28 +176,28 @@
#endif
#else /* !NGX_HAVE_LITTLE_ENDIAN */
-#define ngx_http_v2_huff_encode_buf(dst, buf) \
+#define ngx_http_huff_encode_buf(dst, buf) \
(*(uint64_t *) (dst) = (buf))
#endif
#else /* NGX_PTR_SIZE == 4 */
-#define ngx_http_v2_huff_encode_buf(dst, buf) \
+#define ngx_http_huff_encode_buf(dst, buf) \
(*(uint32_t *) (dst) = htonl(buf))
#endif
size_t
-ngx_http_v2_huff_encode(u_char *src, size_t len, u_char *dst, ngx_uint_t lower)
+ngx_http_huff_encode(u_char *src, size_t len, u_char *dst, ngx_uint_t lower)
{
- u_char *end;
- size_t hlen;
- ngx_uint_t buf, pending, code;
- ngx_http_v2_huff_encode_code_t *table, *next;
+ u_char *end;
+ size_t hlen;
+ ngx_uint_t buf, pending, code;
+ ngx_http_huff_encode_code_t *table, *next;
- table = lower ? ngx_http_v2_huff_encode_table_lc
- : ngx_http_v2_huff_encode_table;
+ table = lower ? ngx_http_huff_encode_table_lc
+ : ngx_http_huff_encode_table;
hlen = 0;
buf = 0;
pending = 0;
@@ -224,7 +224,7 @@
buf |= code >> pending;
- ngx_http_v2_huff_encode_buf(&dst[hlen], buf);
+ ngx_http_huff_encode_buf(&dst[hlen], buf);
hlen += sizeof(buf);
diff --git a/src/http/v2/ngx_http_v2.c b/src/http/v2/ngx_http_v2.c
index 3afa8b6..0e45a7b 100644
--- a/src/http/v2/ngx_http_v2.c
+++ b/src/http/v2/ngx_http_v2.c
@@ -1600,10 +1600,10 @@
h2c->state.length -= size;
h2c->state.field_rest -= size;
- if (ngx_http_v2_huff_decode(&h2c->state.field_state, pos, size,
- &h2c->state.field_end,
- h2c->state.field_rest == 0,
- h2c->connection->log)
+ if (ngx_http_huff_decode(&h2c->state.field_state, pos, size,
+ &h2c->state.field_end,
+ h2c->state.field_rest == 0,
+ h2c->connection->log)
!= NGX_OK)
{
ngx_log_error(NGX_LOG_INFO, h2c->connection->log, 0,
diff --git a/src/http/v2/ngx_http_v2.h b/src/http/v2/ngx_http_v2.h
index 0eceae3..70ee287 100644
--- a/src/http/v2/ngx_http_v2.h
+++ b/src/http/v2/ngx_http_v2.h
@@ -311,12 +311,6 @@
ngx_int_t ngx_http_v2_table_size(ngx_http_v2_connection_t *h2c, size_t size);
-ngx_int_t ngx_http_v2_huff_decode(u_char *state, u_char *src, size_t len,
- u_char **dst, ngx_uint_t last, ngx_log_t *log);
-size_t ngx_http_v2_huff_encode(u_char *src, size_t len, u_char *dst,
- ngx_uint_t lower);
-
-
#define ngx_http_v2_prefix(bits) ((1 << (bits)) - 1)
diff --git a/src/http/v2/ngx_http_v2_encode.c b/src/http/v2/ngx_http_v2_encode.c
index ac79208..8798aa9 100644
--- a/src/http/v2/ngx_http_v2_encode.c
+++ b/src/http/v2/ngx_http_v2_encode.c
@@ -20,7 +20,7 @@
{
size_t hlen;
- hlen = ngx_http_v2_huff_encode(src, len, tmp, lower);
+ hlen = ngx_http_huff_encode(src, len, tmp, lower);
if (hlen > 0) {
*dst = NGX_HTTP_V2_ENCODE_HUFF;