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

Side by Side Diff: net/base/data_url.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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « content/child/web_url_loader_impl.cc ('k') | net/base/data_url_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // NOTE: based loosely on mozilla's nsDataChannel.cpp 5 // NOTE: based loosely on mozilla's nsDataChannel.cpp
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "net/base/data_url.h" 9 #include "net/base/data_url.h"
10 10
11 #include "base/base64.h" 11 #include "base/base64.h"
12 #include "base/basictypes.h" 12 #include "base/basictypes.h"
13 #include "base/strings/string_split.h" 13 #include "base/strings/string_split.h"
14 #include "base/strings/string_util.h" 14 #include "base/strings/string_util.h"
15 #include "net/base/escape.h" 15 #include "net/base/escape.h"
16 #include "net/base/mime_util.h" 16 #include "net/base/mime_util.h"
17 #include "net/http/http_util.h"
17 #include "url/gurl.h" 18 #include "url/gurl.h"
18 19
19 namespace net { 20 namespace net {
20 21
21 // static 22 // static
22 bool DataURL::Parse(const GURL& url, std::string* mime_type, 23 bool DataURL::Parse(const GURL& url, std::string* mime_type,
23 std::string* charset, std::string* data) { 24 std::string* charset, std::string* data) {
24 DCHECK(mime_type->empty()); 25 DCHECK(mime_type->empty());
25 DCHECK(charset->empty()); 26 DCHECK(charset->empty());
26 std::string::const_iterator begin = url.spec().begin(); 27 std::string::const_iterator begin = url.spec().begin();
(...skipping 23 matching lines...) Expand all
50 static const char kCharsetTag[] = "charset="; 51 static const char kCharsetTag[] = "charset=";
51 const size_t kCharsetTagLength = arraysize(kCharsetTag) - 1; 52 const size_t kCharsetTagLength = arraysize(kCharsetTag) - 1;
52 53
53 bool base64_encoded = false; 54 bool base64_encoded = false;
54 for (; iter != meta_data.end(); ++iter) { 55 for (; iter != meta_data.end(); ++iter) {
55 if (!base64_encoded && *iter == kBase64Tag) { 56 if (!base64_encoded && *iter == kBase64Tag) {
56 base64_encoded = true; 57 base64_encoded = true;
57 } else if (charset->empty() && 58 } else if (charset->empty() &&
58 iter->compare(0, kCharsetTagLength, kCharsetTag) == 0) { 59 iter->compare(0, kCharsetTagLength, kCharsetTag) == 0) {
59 charset->assign(iter->substr(kCharsetTagLength)); 60 charset->assign(iter->substr(kCharsetTagLength));
61 // The grammar for charset is not specially defined in RFC2045 and
62 // RFC2397. It just needs to be a token.
63 if (!net::HttpUtil::IsToken(*charset))
64 return false;
60 } 65 }
61 } 66 }
62 67
63 if (mime_type->empty()) { 68 if (mime_type->empty()) {
64 // fallback to defaults if nothing specified in the URL: 69 // fallback to defaults if nothing specified in the URL:
65 mime_type->assign("text/plain"); 70 mime_type->assign("text/plain");
66 } else if (!ParseMimeTypeWithoutParameter(*mime_type, NULL, NULL)) { 71 } else if (!ParseMimeTypeWithoutParameter(*mime_type, NULL, NULL)) {
67 return false; 72 return false;
68 } 73 }
69 if (charset->empty()) 74 if (charset->empty())
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
118 temp_data.resize(length + padding_needed, '='); 123 temp_data.resize(length + padding_needed, '=');
119 } 124 }
120 return base::Base64Decode(temp_data, data); 125 return base::Base64Decode(temp_data, data);
121 } 126 }
122 127
123 temp_data.swap(*data); 128 temp_data.swap(*data);
124 return true; 129 return true;
125 } 130 }
126 131
127 } // namespace net 132 } // namespace net
OLDNEW
« no previous file with comments | « content/child/web_url_loader_impl.cc ('k') | net/base/data_url_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698