Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2349)

Unified Diff: mojo/services/html_viewer/weburlloader_impl.cc

Issue 566453002: Fix Mojo's WebURLLoader so that it provides protocol version and headers. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: mojo/services/html_viewer/weburlloader_impl.cc
diff --git a/mojo/services/html_viewer/weburlloader_impl.cc b/mojo/services/html_viewer/weburlloader_impl.cc
index 39afbc2aadfb49204b86d0280b6f3df2fa0749c3..fb82bcff7579936348db0baf5989e1df4f1a2792 100644
--- a/mojo/services/html_viewer/weburlloader_impl.cc
+++ b/mojo/services/html_viewer/weburlloader_impl.cc
@@ -6,6 +6,7 @@
#include "base/bind.h"
#include "base/logging.h"
+#include "base/strings/string_util.h"
#include "base/thread_task_runner_handle.h"
#include "mojo/common/common_type_converters.h"
#include "mojo/services/html_viewer/blink_url_request_type_converters.h"
@@ -19,12 +20,27 @@
namespace mojo {
namespace {
+static blink::WebURLResponse::HTTPVersion StatusLineToHTTPVersion(
+ const String& status_line) {
+ if (status_line.is_null())
+ return blink::WebURLResponse::HTTP_0_9;
+
+ if (StartsWithASCII(status_line, "HTTP/1.0", true))
+ return blink::WebURLResponse::HTTP_1_0;
+
+ if (StartsWithASCII(status_line, "HTTP/1.1", true))
+ return blink::WebURLResponse::HTTP_1_1;
+
+ return blink::WebURLResponse::Unknown;
+}
+
blink::WebURLResponse ToWebURLResponse(const URLResponsePtr& url_response) {
blink::WebURLResponse result;
result.initialize();
result.setURL(GURL(url_response->url));
result.setMIMEType(blink::WebString::fromUTF8(url_response->mime_type));
result.setTextEncodingName(blink::WebString::fromUTF8(url_response->charset));
+ result.setHTTPVersion(StatusLineToHTTPVersion(url_response->status_line));
result.setHTTPStatusCode(url_response->status_code);
// TODO(darin): Initialize timing properly.
@@ -32,7 +48,22 @@ blink::WebURLResponse ToWebURLResponse(const URLResponsePtr& url_response) {
timing.initialize();
result.setLoadTiming(timing);
- // TODO(darin): Copy other fields.
+ for (size_t i = 0; i < url_response->headers.size(); ++i) {
+ const std::string& header_line = url_response->headers[i];
+ size_t first_colon = header_line.find(":");
+
+ if (first_colon == std::string::npos || first_colon == 0)
+ continue;
+
+ std::string value;
+ TrimWhitespaceASCII(header_line.substr(first_colon + 1),
+ base::TRIM_LEADING,
+ &value);
+ result.setHTTPHeaderField(
+ blink::WebString::fromUTF8(header_line.substr(0, first_colon)),
+ blink::WebString::fromUTF8(value));
+ }
+
return result;
}
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698