diff options
Diffstat (limited to 'webkit')
-rw-r--r-- | webkit/glue/multipart_response_delegate.cc | 9 | ||||
-rw-r--r-- | webkit/glue/multipart_response_delegate.h | 3 | ||||
-rw-r--r-- | webkit/glue/multipart_response_delegate_unittest.cc | 38 |
3 files changed, 36 insertions, 14 deletions
diff --git a/webkit/glue/multipart_response_delegate.cc b/webkit/glue/multipart_response_delegate.cc index a5420b6..2306760 100644 --- a/webkit/glue/multipart_response_delegate.cc +++ b/webkit/glue/multipart_response_delegate.cc @@ -7,6 +7,7 @@ #include "base/logging.h" #include "base/string_util.h" #include "net/base/net_util.h" +#include "net/http/http_util.h" #include "third_party/WebKit/WebKit/chromium/public/WebHTTPHeaderVisitor.h" #include "third_party/WebKit/WebKit/chromium/public/WebString.h" #include "third_party/WebKit/WebKit/chromium/public/WebURL.h" @@ -206,8 +207,12 @@ bool MultipartResponseDelegate::ParseHeaders() { // Create a WebURLResponse based on the original set of headers + the // replacement headers. We only replace the same few headers that gecko // does. See netwerk/streamconv/converters/nsMultiMixedConv.cpp. - std::string mime_type = net::GetSpecificHeader(headers, "content-type"); - std::string charset = net::GetHeaderParamValue(mime_type, "charset"); + std::string content_type = net::GetSpecificHeader(headers, "content-type"); + std::string mime_type; + std::string charset; + bool has_charset = false; + net::HttpUtil::ParseContentType(content_type, &mime_type, &charset, + &has_charset); WebURLResponse response(original_response_.url()); response.setMIMEType(StdStringToWebString(mime_type)); response.setTextEncodingName(StdStringToWebString(charset)); diff --git a/webkit/glue/multipart_response_delegate.h b/webkit/glue/multipart_response_delegate.h index 6a558b7..8ac496e 100644 --- a/webkit/glue/multipart_response_delegate.h +++ b/webkit/glue/multipart_response_delegate.h @@ -51,6 +51,7 @@ #include <string> +#include "base/basictypes.h" #include "third_party/WebKit/WebKit/chromium/public/WebURLResponse.h" namespace WebKit { @@ -128,6 +129,8 @@ class MultipartResponseDelegate { // true when we're done sending information. At that point, we stop // processing AddData requests. bool stop_sending_; + + DISALLOW_COPY_AND_ASSIGN(MultipartResponseDelegate); }; } // namespace webkit_glue diff --git a/webkit/glue/multipart_response_delegate_unittest.cc b/webkit/glue/multipart_response_delegate_unittest.cc index 5c57265..846f323 100644 --- a/webkit/glue/multipart_response_delegate_unittest.cc +++ b/webkit/glue/multipart_response_delegate_unittest.cc @@ -160,18 +160,32 @@ TEST(MultipartResponseTest, Functions) { delegate_tester.data().assign(test_header); EXPECT_TRUE(delegate_tester.ParseHeaders()); EXPECT_TRUE(delegate_tester.data().length() == 0); - EXPECT_EQ(webkit_glue::WebStringToStdString( - client.response_.httpHeaderField( - WebString::fromUTF8("Content-Type"))), - string("image/png")); - EXPECT_EQ(webkit_glue::WebStringToStdString( - client.response_.httpHeaderField( - WebString::fromUTF8("content-length"))), - string("10")); + EXPECT_EQ(string("image/png"), + webkit_glue::WebStringToStdString( + client.response_.httpHeaderField( + WebString::fromUTF8("Content-Type")))); + EXPECT_EQ(string("10"), + webkit_glue::WebStringToStdString( + client.response_.httpHeaderField( + WebString::fromUTF8("content-length")))); // This header is passed from the original request. - EXPECT_EQ(webkit_glue::WebStringToStdString( - client.response_.httpHeaderField(WebString::fromUTF8("foo"))), - string("Bar")); + EXPECT_EQ(string("Bar"), + webkit_glue::WebStringToStdString( + client.response_.httpHeaderField(WebString::fromUTF8("foo")))); + + // Make sure we parse the right mime-type if a charset is provided. + client.Reset(); + string test_header2("content-type: text/html; charset=utf-8\n\n"); + delegate_tester.data().assign(test_header2); + EXPECT_TRUE(delegate_tester.ParseHeaders()); + EXPECT_TRUE(delegate_tester.data().length() == 0); + EXPECT_EQ(string("text/html; charset=utf-8"), + webkit_glue::WebStringToStdString( + client.response_.httpHeaderField( + WebString::fromUTF8("Content-Type")))); + EXPECT_EQ(string("utf-8"), + webkit_glue::WebStringToStdString( + client.response_.textEncodingName())); // FindBoundary tests struct { @@ -247,7 +261,7 @@ TEST(MultipartResponseTest, MissingBoundaries) { "Content-type: text/plain\n\n" "This is a sample response\n"); delegate3.OnReceivedData(no_boundaries.c_str(), - static_cast<int>(no_boundaries.length())); + static_cast<int>(no_boundaries.length())); EXPECT_EQ(1, client.received_response_); EXPECT_EQ(0, client.received_data_); EXPECT_EQ(string(), client.data_); |