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.
This commit is contained in:
Adrien Destugues
2015-01-05 16:22:55 +01:00
parent b5832c1759
commit 71c761d99b
+7 -1
View File
@@ -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<BPositionIO*>(fOptInputData);
if (seekableData)
seekableData->Seek(0, SEEK_SET);
for (;;) {
char outputTempBuffer[kHttpBufferSize];
ssize_t read = fOptInputData->Read(outputTempBuffer,