1
0
mirror of https://github.com/pgbackrest/pgbackrest.git synced 2025-03-03 14:52:21 +02:00

Handle missing reason phrase in HTTP response.

Reason phrases (e.g. OK) are optional in HTTP 1.1 but the space after the status code is not. When the reason phrase was missing the required space was trimmed along with the trailing CR leading to a format error.

Rework the logic to preserve the space and allow empty reason phrases.

Found while testing against the Backblaze S3-compatible API.
This commit is contained in:
David Steele 2020-05-19 08:20:33 -04:00
parent cffdadad92
commit a3d9d9a387
3 changed files with 19 additions and 6 deletions

View File

@ -41,6 +41,14 @@
<p>The <cmd>expire</cmd> command now checks if a stop file is present.</p>
</release-item>
<release-item>
<release-item-contributor-list>
<release-item-ideator id="ctenuun"/>
</release-item-contributor-list>
<p>Handle missing reason phrase in HTTP response.</p>
</release-item>
<release-item>
<release-item-contributor-list>
<release-item-ideator id="eric.radman"/>
@ -8149,6 +8157,11 @@
<contributor-id type="github">cjames53</contributor-id>
</contributor>
<contributor id="ctenuun">
<contributor-name-display>Tenuun</contributor-name-display>
<contributor-id type="github">ctenuun</contributor-id>
</contributor>
<contributor id="cynthia.shang">
<contributor-name-display>Cynthia Shang</contributor-name-display>
<contributor-id type="github">cmwshang</contributor-id>

View File

@ -320,13 +320,13 @@ httpClientRequest(
ioWriteFlush(tlsSessionIoWrite(this->tlsSession));
// Read status and make sure it starts with the correct http version
String *status = strTrim(ioReadLine(tlsSessionIoRead(this->tlsSession)));
String *status = ioReadLine(tlsSessionIoRead(this->tlsSession));
if (!strBeginsWith(status, HTTP_VERSION_STR))
THROW_FMT(FormatError, "http version of response '%s' must be " HTTP_VERSION, strPtr(status));
THROW_FMT(FormatError, "http version of response '%s' must be " HTTP_VERSION, strPtr(strTrim(status)));
// Now read the response code and message
status = strSub(status, sizeof(HTTP_VERSION));
// Now read the response code and message (and strip the trailing CR)
status = strSubN(status, sizeof(HTTP_VERSION), strSize(status) - sizeof(HTTP_VERSION) - 1);
int spacePos = strChr(status, ' ');

View File

@ -230,7 +230,7 @@ testHttpServer(void)
"\r\n");
harnessTlsServerReply(
"HTTP/1.1 403 Auth Error\r\n"
"HTTP/1.1 403 \r\n"
"content-length:7\r\n"
"\r\n"
"CONTENT");
@ -576,7 +576,7 @@ testRun(void)
buffer, httpClientRequest(client, strNew("GET"), strNew("/"), NULL, NULL, NULL, false),
"error with content length");
TEST_RESULT_UINT(httpClientResponseCode(client), 403, " check response code");
TEST_RESULT_STR_Z(httpClientResponseMessage(client), "Auth Error", " check response message");
TEST_RESULT_STR_Z(httpClientResponseMessage(client), "", " check empty response message");
TEST_RESULT_STR_Z(
httpHeaderToLog(httpClientResponseHeader(client)), "{content-length: '7'}", " check response headers");
TEST_RESULT_STR_Z(strNewBuf(buffer), "CONTENT", " check response");