{
struct allocated_headers * ah = wsi->u.http2.http.ah;
- if (!hdr_token_idx)
+ if (!hdr_token_idx) {
+ lwsl_err("%s: zero hdr_token_idx\n", __func__);
return 1;
+ }
- if (ah->nfrag >= ARRAY_SIZE(ah->frag_index))
+ if (ah->nfrag >= ARRAY_SIZE(ah->frag_index)) {
+ lwsl_err("%s: frag index %d too big\n", __func__, ah->nfrag);
return 1;
+ }
ah->frags[ah->nfrag].offset = ah->pos;
ah->frags[ah->nfrag].len = 0;
ah->data[ah->pos++] = c;
ah->frags[ah->nfrag].len++;
- return ah->pos >= sizeof(ah->data);
+ return ah->pos >= wsi->context->max_http_header_data;
}
static int lws_frag_end(struct lws *wsi)
return 0;
}
-int lws_hpack_interpret(struct lws_context *context,
- struct lws *wsi, unsigned char c)
+int lws_hpack_interpret(struct lws *wsi, unsigned char c)
{
unsigned int prev;
unsigned char c1;
int n;
+ lwsl_debug(" state %d\n", wsi->u.http2.hpack);
+
switch (wsi->u.http2.hpack) {
case HPKS_OPT_PADDING:
wsi->u.http2.padding = c;
if (c & 0x80) { /* indexed header field only */
/* just a possibly-extended integer */
wsi->u.http2.hpack_type = HPKT_INDEXED_HDR_7;
+ lwsl_debug("HKPS_TYPE setting header_index %d\n", c & 0x7f);
wsi->u.http2.header_index = c & 0x7f;
if ((c & 0x7f) == 0x7f) {
wsi->u.http2.hpack_len = c & 0x7f;
wsi->u.http2.hpack = HPKS_IDX_EXT;
break;
}
+ lwsl_debug("HKPS_TYPE: %d\n", c & 0x7f);
if (lws_write_indexed_hdr(wsi, c & 0x7f))
return 1;
/* stay at same state */
* H + possibly-extended value length
* literal value
*/
+ lwsl_debug("HKPS_TYPE 2 setting header_index %d\n", 0);
wsi->u.http2.header_index = 0;
if (c == 0x40) { /* literal name */
wsi->u.http2.hpack_type = HPKT_LITERAL_HDR_VALUE_INCR;
wsi->u.http2.hpack = HPKS_IDX_EXT;
break;
}
+ lwsl_debug("HKPS_TYPE 3 setting header_index %d\n", c & 0x3f);
wsi->u.http2.header_index = c & 0x3f;
wsi->u.http2.value = 1;
wsi->u.http2.hpack = HPKS_HLEN;
wsi->u.http2.value = 0;
break;
}
+ //lwsl_debug("indexed\n");
/* indexed name */
wsi->u.http2.hpack_type = HPKT_INDEXED_HDR_4_VALUE;
wsi->u.http2.header_index = 0;
wsi->u.http2.hpack = HPKS_IDX_EXT;
break;
}
+ //lwsl_err("HKPS_TYPE 5 setting header_index %d\n", c & 0xf);
wsi->u.http2.header_index = c & 0xf;
wsi->u.http2.value = 1;
wsi->u.http2.hpack = HPKS_HLEN;
if (!(c & 0x80)) {
switch (wsi->u.http2.hpack_type) {
case HPKT_INDEXED_HDR_7:
+ //lwsl_err("HKPS_IDX_EXT hdr idx %d\n", wsi->u.http2.hpack_len);
if (lws_write_indexed_hdr(wsi, wsi->u.http2.hpack_len))
return 1;
wsi->u.http2.hpack = HPKS_TYPE;
break;
default:
+ // lwsl_err("HKPS_IDX_EXT setting header_index %d\n",
+ // wsi->u.http2.hpack_len);
wsi->u.http2.header_index = wsi->u.http2.hpack_len;
wsi->u.http2.value = 1;
wsi->u.http2.hpack = HPKS_HLEN;
if (wsi->u.http2.hpack_len < 0x7f) {
pre_data:
if (wsi->u.http2.value) {
+ if (wsi->u.http2.header_index)
if (lws_frag_start(wsi, lws_token_from_index(wsi,
wsi->u.http2.header_index,
- NULL, NULL)))
+ NULL, NULL))) {
+ // lwsl_notice("%s: hlen failed\n", __func__);
return 1;
+ }
} else
wsi->u.hdr.parser_state = WSI_TOKEN_NAME_PART;
wsi->u.http2.hpack = HPKS_DATA;
c1 = c;
}
if (wsi->u.http2.value) { /* value */
- if (lws_frag_append(wsi, c1))
- return 1;
+ if (wsi->u.http2.header_index)
+ if (lws_frag_append(wsi, c1))
+ return 1;
} else { /* name */
if (lws_parse(wsi, c1))
return 1;
if (wsi->u.http2.value) {
if (lws_frag_end(wsi))
return 1;
-
+ // lwsl_err("data\n");
lws_dump_header(wsi, lws_token_from_index(
wsi, wsi->u.http2.header_index,
NULL, NULL));
else
wsi->u.http2.hpack = HPKS_TYPE;
} else { /* name */
- if (wsi->u.hdr.parser_state < WSI_TOKEN_COUNT)
+ //if (wsi->u.hdr.parser_state < WSI_TOKEN_COUNT)
wsi->u.http2.value = 1;
wsi->u.http2.hpack = HPKS_HLEN;
return 0;
}
-int lws_add_http2_header_by_name(struct lws_context *context, struct lws *wsi,
+int lws_add_http2_header_by_name(struct lws *wsi,
const unsigned char *name,
const unsigned char *value, int length,
unsigned char **p, unsigned char *end)
return 0;
}
-int lws_add_http2_header_by_token(struct lws_context *context, struct lws *wsi,
- enum lws_token_indexes token,
+int lws_add_http2_header_by_token(struct lws *wsi, enum lws_token_indexes token,
const unsigned char *value, int length,
unsigned char **p, unsigned char *end)
{
if (!name)
return 1;
- return lws_add_http2_header_by_name(context, wsi, name, value,
- length, p, end);
+ return lws_add_http2_header_by_name(wsi, name, value, length, p, end);
}
-int lws_add_http2_header_status(struct lws_context *context, struct lws *wsi,
+int lws_add_http2_header_status(struct lws *wsi,
unsigned int code, unsigned char **p,
unsigned char *end)
{
wsi->u.http2.send_END_STREAM = !!(code >= 400);
n = sprintf((char *)status, "%u", code);
- if (lws_add_http2_header_by_token(context, wsi,
- WSI_TOKEN_HTTP_COLON_STATUS, status,
- n, p, end))
+ if (lws_add_http2_header_by_token(wsi, WSI_TOKEN_HTTP_COLON_STATUS,
+ status, n, p, end))
+
return 1;
return 0;