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

Unified Diff: net/url_request/url_request_data_job.cc

Issue 294193002: Set response headers for data URL. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
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 | « net/url_request/url_request_data_job.h ('k') | net/url_request/url_request_data_job_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/url_request/url_request_data_job.cc
diff --git a/net/url_request/url_request_data_job.cc b/net/url_request/url_request_data_job.cc
index fd248c7d07a30ba4536d761bae561ee801a09cd9..e0746467079836f42aff97cdbe2029b6e5669eb9 100644
--- a/net/url_request/url_request_data_job.cc
+++ b/net/url_request/url_request_data_job.cc
@@ -8,9 +8,41 @@
#include "net/base/data_url.h"
#include "net/base/net_errors.h"
+#include "net/http/http_response_headers.h"
+#include "url/gurl.h"
namespace net {
+int URLRequestDataJob::BuildResponse(const GURL& url,
+ std::string* mime_type,
+ std::string* charset,
+ std::string* data,
+ HttpResponseHeaders* headers) {
+ if (!net::DataURL::Parse(url, mime_type, charset, data))
+ return net::ERR_INVALID_URL;
+
+ // |mime_type| set by net::DataURL::Parse() is guaranteed to be in
+ // token "/" token
+ // form. |charset| is also guaranteed to be a token.
+
+ DCHECK(!mime_type->empty());
+ DCHECK(!charset->empty());
+
+ if (headers) {
+ headers->ReplaceStatusLine("HTTP/1.1 200 OK");
+ // "charset" in the Content-Type header is specified explicitly to follow
+ // the "token" ABNF in the HTTP spec. When DataURL::Parse() call is
+ // successful, it's guaranteed that the string in |charset| follows the
+ // "token" ABNF.
+ std::string content_type_header =
+ "Content-Type: " + *mime_type + ";charset=" + *charset;
+ headers->AddHeader(content_type_header);
+ headers->AddHeader("Access-Control-Allow-Origin: *");
+ }
+
+ return net::OK;
+}
+
URLRequestDataJob::URLRequestDataJob(
URLRequest* request, NetworkDelegate* network_delegate)
: URLRequestSimpleJob(request, network_delegate) {
@@ -25,7 +57,10 @@ int URLRequestDataJob::GetData(std::string* mime_type,
const GURL& url = request_->url();
if (!url.is_valid())
return ERR_INVALID_URL;
- return DataURL::Parse(url, mime_type, charset, data)? OK: ERR_INVALID_URL;
+
+ // TODO(tyoshino): Get the headers and export via
+ // URLRequestJob::GetResponseInfo().
+ return BuildResponse(url, mime_type, charset, data, NULL);
}
URLRequestDataJob::~URLRequestDataJob() {
« no previous file with comments | « net/url_request/url_request_data_job.h ('k') | net/url_request/url_request_data_job_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698