Commit 36c9ee84 authored by zea@chromium.org's avatar zea@chromium.org

Revert 138168 - net: Fix a regression that broke file uploading with http authentication

Failing net_unit_tests RequestSocketsMultipleTimesDoesNothing.

When uploading a file with http authentication, UploadData is reused
for a new UploadDataStream. Hence, we should close the files in UploadData
if already opened and read, so we can reread the files from the beginning.

The regression was caused by r123677.  Special thanks to thomas.themel for
identifying the offending patch and helping us to fix the issue.

BUG=128574
TEST=added a unit test; manually confirmed that uploading a file with basic authentication, and multi-round authentication with NTLM and Negotiate worked.

Review URL: https://chromiumcodereview.appspot.com/10408042

TBR=satorux@chromium.org
Review URL: https://chromiumcodereview.appspot.com/10388221

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@138175 0039d316-1c4b-4281-b951-d872f2087c98
parent bacbac5a
...@@ -114,20 +114,6 @@ uint64 UploadData::Element::BytesRemaining() { ...@@ -114,20 +114,6 @@ uint64 UploadData::Element::BytesRemaining() {
return GetContentLength() - offset_; return GetContentLength() - offset_;
} }
void UploadData::Element::ResetOffset() {
offset_ = 0;
// Delete the file stream if already opened, so we can reread the file from
// the beginning.
if (file_stream_) {
// Temporarily allow until fix: http://crbug.com/72001.
base::ThreadRestrictions::ScopedAllowIO allow_io;
file_stream_->CloseSync();
delete file_stream_;
file_stream_ = NULL;
}
}
FileStream* UploadData::Element::OpenFileStream() { FileStream* UploadData::Element::OpenFileStream() {
scoped_ptr<FileStream> file(new FileStream(NULL)); scoped_ptr<FileStream> file(new FileStream(NULL));
int64 rv = file->OpenSync( int64 rv = file->OpenSync(
......
...@@ -129,9 +129,8 @@ class NET_EXPORT UploadData ...@@ -129,9 +129,8 @@ class NET_EXPORT UploadData
// Returns the number of bytes remaining to read. // Returns the number of bytes remaining to read.
uint64 BytesRemaining(); uint64 BytesRemaining();
// Resets the offset to zero and closes the file stream if opened, so // Resets the offset to zero, so that the element can be reread.
// that the element can be reread. void ResetOffset() { offset_ = 0; }
void ResetOffset();
private: private:
// Returns a FileStream opened for reading for this element, positioned // Returns a FileStream opened for reading for this element, positioned
......
...@@ -27,17 +27,6 @@ const char kTestData[] = "0123456789"; ...@@ -27,17 +27,6 @@ const char kTestData[] = "0123456789";
const size_t kTestDataSize = arraysize(kTestData) - 1; const size_t kTestDataSize = arraysize(kTestData) - 1;
const size_t kTestBufferSize = 1 << 14; // 16KB. const size_t kTestBufferSize = 1 << 14; // 16KB.
// Reads data from the upload data stream, and returns the data as string.
std::string ReadFromUploadDataStream(UploadDataStream* stream) {
std::string data_read;
scoped_refptr<IOBuffer> buf = new IOBuffer(kTestBufferSize);
while (!stream->IsEOF()) {
const int bytes_read = stream->Read(buf, kTestBufferSize);
data_read.append(buf->data(), bytes_read);
}
return data_read;
}
} // namespace } // namespace
class UploadDataStreamTest : public PlatformTest { class UploadDataStreamTest : public PlatformTest {
...@@ -155,36 +144,4 @@ TEST_F(UploadDataStreamTest, FileChanged) { ...@@ -155,36 +144,4 @@ TEST_F(UploadDataStreamTest, FileChanged) {
file_util::Delete(temp_file_path, false); file_util::Delete(temp_file_path, false);
} }
TEST_F(UploadDataStreamTest, UploadDataReused) {
FilePath temp_file_path;
ASSERT_TRUE(file_util::CreateTemporaryFile(&temp_file_path));
ASSERT_EQ(static_cast<int>(kTestDataSize),
file_util::WriteFile(temp_file_path, kTestData, kTestDataSize));
// Prepare |upload_data_| that contains a file.
std::vector<UploadData::Element> elements;
UploadData::Element element;
element.SetToFilePath(temp_file_path);
elements.push_back(element);
upload_data_->SetElements(elements);
EXPECT_EQ(kTestDataSize, upload_data_->GetContentLengthSync());
// Confirm that the file is read properly.
{
UploadDataStream stream(upload_data_);
ASSERT_EQ(OK, stream.Init());
EXPECT_EQ(kTestData, ReadFromUploadDataStream(&stream));
}
// Reuse |upload_data_| for another UploadDataStream, and confirm that the
// file is read properly.
{
UploadDataStream stream(upload_data_);
ASSERT_EQ(OK, stream.Init());
EXPECT_EQ(kTestData, ReadFromUploadDataStream(&stream));
}
file_util::Delete(temp_file_path, false);
}
} // namespace net } // namespace net
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment