From 44cff45d3d2390290803e802d0fa5a2079485da8 Mon Sep 17 00:00:00 2001 From: Adrien Destugues Date: Mon, 20 Aug 2018 08:02:34 +0200 Subject: [PATCH] HttpRequest: chunk length are in hex Thanks to mmlr for spotting this. The wrong format specifier was used, which would lead the server to get the wrong size and do strange things. Chunked uploads should now work a lot better. While I was at it, put the line termination in the printf to save a write to the socket (these are unbuffered and each of them costs us a syscall, and in some cases this has been found to confuse webservers as we end up sending super small TCP packets). --- src/kits/network/libnetapi/HttpRequest.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/kits/network/libnetapi/HttpRequest.cpp b/src/kits/network/libnetapi/HttpRequest.cpp index 6cdee45d77..95c2654588 100644 --- a/src/kits/network/libnetapi/HttpRequest.cpp +++ b/src/kits/network/libnetapi/HttpRequest.cpp @@ -1076,12 +1076,13 @@ BHttpRequest::_SendPostData() break; if (fOptInputDataSize < 0) { - // Chunked transfer - char hexSize[20]; - size_t hexLength = sprintf(hexSize, "%ld", read); + // Input data size unknown, so we have to use chunked transfer + char hexSize[18]; + // The string does not need to be NULL terminated. + size_t hexLength = snprintf(hexSize, sizeof(hexSize), "%lx\r\n", + read); fSocket->Write(hexSize, hexLength); - fSocket->Write("\r\n", 2); fSocket->Write(outputTempBuffer, read); fSocket->Write("\r\n", 2); } else {