pgbackrest.git / summary / log / commit / refs
commit 3bdba4933d45451a3fa6f5dafcb79fd976bffef6
Author: David Steele <david@crunchydata.com>
Date: Wed Jul 17 20:49:42 2019 +0000
Fix incorrect handling of transfer-encoding response to HEAD request.
The HTTP server can use either content-length or transfer-encoding to indicate that there is content in the response. HEAD requests do not include content but return all the same headers as GET. In the HEAD case we were ignoring content-length but not transfer-encoding which led to unexpected eof errors on AWS S3. Our test server, minio, uses content-length so this was not caught in integration testing.
Ignore all content for HEAD requests (no matter how it is reported) and add a unit test for transfer-encoding to prevent a regression.
Found by Pavel Suderevsky.
doc/xml/release.xml | 13 +++++++++++++
src/common/io/http/client.c | 2 +-
test/src/module/common/ioHttpTest.c | 22 ++++++++++++++++++++++
3 files changed, 36 insertions(+), 1 deletion(-)
diff --git a/doc/xml/release.xml b/doc/xml/release.xml
index 5fff392b6..cb01200e5 100644
--- a/doc/xml/release.xml
+++ b/doc/xml/release.xml
@@ -15,6 +15,14 @@
<release date="XXXX-XX-XX" version="2.16dev" title="UNDER DEVELOPMENT">
<release-core-list>
<release-bug-list>
+ <release-item>
+ <release-item-contributor-list>
+ <release-item-ideator id="pavel.suderevsky"/>
+ </release-item-contributor-list>
+
+ <p>Fix incorrect handling of <id>transfer-encoding</id> response to <id>HEAD</id> request.</p>
+ </release-item>
+
<release-item>
<release-item-contributor-list>
<release-item-ideator id="christian.lange"/>
@@ -7441,6 +7449,11 @@
<contributor-id type="github">hitech73</contributor-id>
</contributor>
+ <contributor id="pavel.suderevsky">
+ <contributor-name-display>Pavel Suderevsky</contributor-name-display>
+ <contributor-id type="github">psuderevsky</contributor-id>
+ </contributor>
+
<contributor id="pritam.barhate">
<contributor-name-display>Pritam Barhate</contributor-name-display>
<contributor-id type="github">pritammobisoft</contributor-id>
diff --git a/src/common/io/http/client.c b/src/common/io/http/client.c
index 6e967e005..96c5c0c47 100644
--- a/src/common/io/http/client.c
+++ b/src/common/io/http/client.c
@@ -386,7 +386,7 @@ httpClientRequest(
}
// Was content returned in the response? HEAD will report content but not actually return any.
- bool contentExists = this->contentChunked || (this->contentSize > 0 && !strEq(verb, HTTP_VERB_HEAD_STR));
+ bool contentExists = (this->contentChunked || this->contentSize > 0) && !strEq(verb, HTTP_VERB_HEAD_STR);
this->contentEof = !contentExists;
// If all content should be returned from this function then read the buffer. Also read the reponse if there has
diff --git a/test/src/module/common/ioHttpTest.c b/test/src/module/common/ioHttpTest.c
index c62dce776..9a723af1b 100644
--- a/test/src/module/common/ioHttpTest.c
+++ b/test/src/module/common/ioHttpTest.c
@@ -152,6 +152,16 @@ testHttpServer(void)
"content-length:380\r\n"
"\r\n");
+ // Head request with transfer encoding but no content
+ harnessTlsServerExpect(
+ "HEAD / HTTP/1.1\r\n"
+ "\r\n");
+
+ harnessTlsServerReply(
+ "HTTP/1.1 200 OK\r\n"
+ "Transfer-Encoding: chunked\r\n"
+ "\r\n");
+
// Error with content length 0 (with a few slow down errors)
harnessTlsServerExpect(
"GET / HTTP/1.1\r\n"
@@ -474,6 +484,18 @@ testRun(void)
TEST_RESULT_STR(
strPtr(httpHeaderToLog(httpClientReponseHeader(client))), "{content-length: '380'}", " check response headers");
+ // Head request with transfer encoding but no content
+ TEST_RESULT_VOID(
+ httpClientRequest(client, strNew("HEAD"), strNew("/"), NULL, httpHeaderNew(NULL), NULL, true),
+ "head request with transfer encoding");
+ TEST_RESULT_UINT(httpClientResponseCode(client), 200, " check response code");
+ TEST_RESULT_STR(strPtr(httpClientResponseMessage(client)), "OK", " check response message");
+ TEST_RESULT_BOOL(httpClientEof(client), true, " io is eof");
+ TEST_RESULT_BOOL(httpClientBusy(client), false, " client is not busy");
+ TEST_RESULT_STR(
+ strPtr(httpHeaderToLog(httpClientReponseHeader(client))), "{transfer-encoding: 'chunked'}",
+ " check response headers");
+
// Error with content length 0
TEST_RESULT_VOID(
httpClientRequest(client, strNew("GET"), strNew("/"), NULL, NULL, NULL, false), "error with content length 0");
[parent: 6f981c53bb63]