Skip to content

Commit

Permalink
http: Move chunked buffer pos pointer while parsing
Browse files Browse the repository at this point in the history
Previously, Unit didn't move the buffer pointer when parsing chunked
data because the buffer was not used after sent. It's used for upstream
response. With the new requirement to support request chunked body,
the buffer might be used for pipeline request, so it's necessary to move
the pos pointer while parsing.

Reviewed-by: Andrew Clayton <[email protected]>
  • Loading branch information
hongzhidao committed Jun 13, 2024
1 parent d7ec30c commit 3ec5174
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 9 deletions.
10 changes: 4 additions & 6 deletions src/nxt_http_chunk_parse.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,7 @@ nxt_http_chunk_parse(nxt_task_t *task, nxt_http_chunk_parse_t *hcp,

for (b = in; b != NULL; b = next) {

hcp->pos = b->mem.pos;

while (hcp->pos < b->mem.free) {
while (b->mem.pos < b->mem.free) {
/*
* The sw_chunk state is tested outside the switch
* to preserve hcp->pos and to not touch memory.
Expand All @@ -76,7 +74,7 @@ nxt_http_chunk_parse(nxt_task_t *task, nxt_http_chunk_parse_t *hcp,
/* ret == NXT_HTTP_CHUNK_END */
}

ch = *hcp->pos++;
ch = *b->mem.pos++;

switch (state) {

Expand Down Expand Up @@ -203,7 +201,7 @@ nxt_http_chunk_buffer(nxt_http_chunk_parse_t *hcp, nxt_buf_t ***tail,
size_t size;
nxt_buf_t *b;

p = hcp->pos;
p = in->mem.pos;
size = in->mem.free - p;

b = nxt_buf_mem_alloc(hcp->mem_pool, 0, 0);
Expand All @@ -224,7 +222,7 @@ nxt_http_chunk_buffer(nxt_http_chunk_parse_t *hcp, nxt_buf_t ***tail,

if (hcp->chunk_size < size) {
p += hcp->chunk_size;
hcp->pos = p;
in->mem.pos = p;

b->mem.free = p;
b->mem.end = p;
Expand Down
3 changes: 0 additions & 3 deletions src/nxt_http_parse.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,8 @@ struct nxt_http_field_s {


typedef struct {
u_char *pos;
nxt_mp_t *mem_pool;

uint64_t chunk_size;

uint8_t state;
uint8_t last; /* 1 bit */
uint8_t chunk_error; /* 1 bit */
Expand Down

0 comments on commit 3ec5174

Please sign in to comment.