From f8679425118f333f7b57c565fed514d22eb89b05 Mon Sep 17 00:00:00 2001 From: Stefan Eissing Date: Tue, 21 May 2024 15:51:51 +0200 Subject: [PATCH] test: add test1546, chunked not last transfer encoding with more than one transfer-encoding, 'chunked' must be the last added to the writer stack (and therefore the first to decode). RFC 9112, ch. 6.1. Closes #13736 --- lib/content_encoding.c | 7 +++++ tests/data/Makefile.inc | 2 +- tests/data/test1546 | 63 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 71 insertions(+), 1 deletion(-) create mode 100644 tests/data/test1546 diff --git a/lib/content_encoding.c b/lib/content_encoding.c index d34d3a1f5..69a3e2ac5 100644 --- a/lib/content_encoding.c +++ b/lib/content_encoding.c @@ -994,6 +994,8 @@ CURLcode Curl_build_unencoding_stack(struct Curl_easy *data, const struct Curl_cwtype *cwt; struct Curl_cwriter *writer; + CURL_TRC_WRITE(data, "looking for %s decoder: %.*s", + is_transfer? "transfer" : "content", (int)namelen, name); is_chunked = (is_transfer && (namelen == 7) && strncasecompare(name, "chunked", 7)); /* if we skip the decoding in this phase, do not look further. @@ -1001,6 +1003,8 @@ CURLcode Curl_build_unencoding_stack(struct Curl_easy *data, if((is_transfer && !data->set.http_transfer_encoding && !is_chunked) || (!is_transfer && data->set.http_ce_skip)) { /* not requested, ignore */ + CURL_TRC_WRITE(data, "decoder not requested, ignored: %.*s", + (int)namelen, name); return CURLE_OK; } @@ -1018,6 +1022,7 @@ CURLcode Curl_build_unencoding_stack(struct Curl_easy *data, * "A sender MUST NOT apply the chunked transfer coding more than * once to a message body." */ + CURL_TRC_WRITE(data, "ignoring duplicate 'chunked' decoder"); return CURLE_OK; } @@ -1040,6 +1045,8 @@ CURLcode Curl_build_unencoding_stack(struct Curl_easy *data, cwt = &error_writer; /* Defer error at use. */ result = Curl_cwriter_create(&writer, data, cwt, phase); + CURL_TRC_WRITE(data, "added %s decoder %s -> %d", + is_transfer? "transfer" : "content", cwt->name, result); if(result) return result; diff --git a/tests/data/Makefile.inc b/tests/data/Makefile.inc index 07fc29435..8daba4ed9 100644 --- a/tests/data/Makefile.inc +++ b/tests/data/Makefile.inc @@ -195,7 +195,7 @@ test1508 test1509 test1510 test1511 test1512 test1513 test1514 test1515 \ test1516 test1517 test1518 test1519 test1520 test1521 test1522 test1523 \ test1524 test1525 test1526 test1527 test1528 test1529 test1530 test1531 \ test1532 test1533 test1534 test1535 test1536 test1537 test1538 test1539 \ -test1540 test1541 test1542 test1543 test1544 test1545 \ +test1540 test1541 test1542 test1543 test1544 test1545 test1546 \ \ test1550 test1551 test1552 test1553 test1554 test1555 test1556 test1557 \ test1558 test1559 test1560 test1561 test1562 test1563 test1564 test1565 \ diff --git a/tests/data/test1546 b/tests/data/test1546 new file mode 100644 index 000000000..0ec7093f7 --- /dev/null +++ b/tests/data/test1546 @@ -0,0 +1,63 @@ + + + +HTTP +HTTP GET +Transfer-Encoding + + +# +# Server-side + + +HTTP/1.1 200 OK +Date: Mon, 29 Nov 2004 21:56:53 GMT +Server: Apache +Transfer-Encoding: chunked, gzip + +0 + + + + +HTTP/1.1 200 OK +Date: Mon, 29 Nov 2004 21:56:53 GMT +Server: Apache + + + + +# +# Client-side + + +libz + + +http + + +HTTP transfer-encoding wrong order + + +http://%HOSTIP:%HTTPPORT/%TESTNUMBER --tr-encoding + + + +# +# Verify data after the test has been "shot" + + +GET /%TESTNUMBER HTTP/1.1 +Host: %HOSTIP:%HTTPPORT +User-Agent: curl/%VERSION +Accept: */* +Connection: TE +TE: gzip + + + +61 + + +