From 71c761d99bdc590d853f7a246d14247493008a0e Mon Sep 17 00:00:00 2001 From: Adrien Destugues Date: Mon, 5 Jan 2015 16:22:55 +0100 Subject: [PATCH] HttpRequest: rewind the input data before sending it * This is needed for redirects to work as expected. * It makes it harder to send data starting from the middle of a BPositionIO (you now need a wrapper object), but that is an uncommon feature so it is acceptable. Fixes #11687. --- src/kits/network/libnetapi/HttpRequest.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/kits/network/libnetapi/HttpRequest.cpp b/src/kits/network/libnetapi/HttpRequest.cpp index 0b3b242d0b..3f2f64d7b0 100644 --- a/src/kits/network/libnetapi/HttpRequest.cpp +++ b/src/kits/network/libnetapi/HttpRequest.cpp @@ -98,7 +98,7 @@ BHttpRequest::BHttpRequest(const BHttpRequest& other) fOptHeaders(NULL), fOptPostFields(NULL), fOptInputData(NULL), - fOptInputDataSize(0), + fOptInputDataSize(-1), fOptRangeStart(other.fOptRangeStart), fOptRangeEnd(other.fOptRangeEnd), fOptFollowLocation(other.fOptFollowLocation) @@ -1000,6 +1000,12 @@ BHttpRequest::_SendPostData() } else if ((fRequestMethod == B_HTTP_POST || fRequestMethod == B_HTTP_PUT) && fOptInputData != NULL) { + // If the input data is seekable, we rewind it for each new request. + BPositionIO* seekableData + = dynamic_cast(fOptInputData); + if (seekableData) + seekableData->Seek(0, SEEK_SET); + for (;;) { char outputTempBuffer[kHttpBufferSize]; ssize_t read = fOptInputData->Read(outputTempBuffer,