Skip to content

Commit

Permalink
* modules/http/chunk_filter.c (ap_http_chunk_filter): For a brigade
Browse files Browse the repository at this point in the history
  containing [FLUSH EOS], insert the last-chunk terminator before the
  FLUSH rather than between the FLUSH and the EOS.
  • Loading branch information
notroj committed Dec 20, 2023
1 parent 4889f66 commit cb6cb37
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions modules/http/chunk_filter.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ apr_status_t ap_http_chunk_filter(ap_filter_t *f, apr_bucket_brigade *b)

for (more = tmp = NULL; b; b = more, more = NULL) {
apr_off_t bytes = 0;
apr_bucket *eos = NULL;
apr_bucket *eos = NULL; /* EOS bucket, or FLUSH preceding EOS */
apr_bucket *flush = NULL;
/* XXX: chunk_hdr must remain at this scope since it is used in a
* transient bucket.
Expand Down Expand Up @@ -99,8 +99,20 @@ apr_status_t ap_http_chunk_filter(ap_filter_t *f, apr_bucket_brigade *b)
}
if (APR_BUCKET_IS_FLUSH(e)) {
flush = e;

/* Special case to catch common brigade ending of
* [FLUSH] [EOS] - insert the last_chunk before
* the FLUSH rather than between the FLUSH and the
* EOS. */
if (e != APR_BRIGADE_LAST(b)) {
more = apr_brigade_split_ex(b, APR_BUCKET_NEXT(e), tmp);
if (APR_BUCKET_IS_EOS(APR_BUCKET_NEXT(e))) {
eos = e;
/* anything after EOS is dropped, no need
* to split. */
}
else {
more = apr_brigade_split_ex(b, APR_BUCKET_NEXT(e), tmp);
}
}
break;
}
Expand Down Expand Up @@ -173,10 +185,10 @@ apr_status_t ap_http_chunk_filter(ap_filter_t *f, apr_bucket_brigade *b)
* FLUSH bucket, or appended to the brigade
*/
e = apr_bucket_immortal_create(CRLF_ASCII, 2, c->bucket_alloc);
if (eos != NULL) {
if (flush != NULL) {
APR_BUCKET_INSERT_BEFORE(eos, e);
}
else if (flush != NULL) {
else if (eos != NULL) {
APR_BUCKET_INSERT_BEFORE(flush, e);
}
else {
Expand Down

0 comments on commit cb6cb37

Please sign in to comment.