Skip to content

Commit

Permalink
Don't send a chunked transfer terminator for non-chunked transfers.
Browse files Browse the repository at this point in the history
 * Fixes oversight from previous change.
 * Thanks hamishm for watching !
  • Loading branch information
pulkomandy committed Oct 9, 2013
1 parent 780967d commit a5826aa
Showing 1 changed file with 27 additions and 26 deletions.
53 changes: 27 additions & 26 deletions src/kits/network/libnetapi/HttpRequest.cpp
Expand Up @@ -458,30 +458,33 @@ BHttpRequest::_MakeRequest()
}
} else if ((fRequestMethod == B_HTTP_POST || fRequestMethod == B_HTTP_PUT)
&& fOptInputData != NULL) {
char outputTempBuffer[1024];
ssize_t read = 0;

while (read != -1) {
read = fOptInputData->Read(outputTempBuffer, 1024);

if (read > 0) {
if (fOptInputDataSize < 0)
{
// Chunked transfer
char hexSize[16];
size_t hexLength = sprintf(hexSize, "%ld", read);

fSocket->Write(hexSize, hexLength);
fSocket->Write("\r\n", 2);
fSocket->Write(outputTempBuffer, read);
fSocket->Write("\r\n", 2);
} else {
fSocket->Write(outputTempBuffer, read);
}

for(;;) {
char outputTempBuffer[1024];
ssize_t read = fOptInputData->Read(outputTempBuffer,
sizeof(outputTempBuffer));

if(read <= 0) break;

if (fOptInputDataSize < 0)
{
// Chunked transfer
char hexSize[16];
size_t hexLength = sprintf(hexSize, "%ld", read);

fSocket->Write(hexSize, hexLength);
fSocket->Write("\r\n", 2);
fSocket->Write(outputTempBuffer, read);
fSocket->Write("\r\n", 2);
} else {
fSocket->Write(outputTempBuffer, read);
}
}

fSocket->Write("0\r\n\r\n", 5);
if (fOptInputDataSize < 0) {
// Chunked transfer terminating sequence
fSocket->Write("0\r\n\r\n", 5);
}
}
fOutputBuffer.Truncate(0, true);

Expand Down Expand Up @@ -537,13 +540,11 @@ BHttpRequest::_MakeRequest()
fListener->HeadersReceived(this);

// Parse received cookies
if ((fContext != NULL) && fHeaders.HasHeader("Set-Cookie")) {
if (fContext != NULL) {
for (int32 i = 0; i < fHeaders.CountHeaders(); i++) {
if (fHeaders.HeaderAt(i).NameIs("Set-Cookie")) {
BNetworkCookie* cookie = new BNetworkCookie();
cookie->ParseCookieStringFromUrl(
fContext->GetCookieJar().AddCookie(
fHeaders.HeaderAt(i).Value(), fUrl);
fContext->GetCookieJar().AddCookie(cookie);
}
}
}
Expand Down Expand Up @@ -717,7 +718,7 @@ BHttpRequest::_ParseHeaders()
if (_GetLine(currentHeader) == B_ERROR)
return;

// Empty line
// An empty line means the end of the header section
if (currentHeader.Length() == 0) {
fHeadersReceived = true;
return;
Expand Down

0 comments on commit a5826aa

Please sign in to comment.