OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 #include "content/child/web_url_request_util.h" | 5 #include "content/child/web_url_request_util.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <limits> | 10 #include <limits> |
(...skipping 16 matching lines...) Expand all Loading... |
27 namespace content { | 27 namespace content { |
28 | 28 |
29 namespace { | 29 namespace { |
30 | 30 |
31 const char kThrottledErrorDescription[] = | 31 const char kThrottledErrorDescription[] = |
32 "Request throttled. Visit http://dev.chromium.org/throttling for more " | 32 "Request throttled. Visit http://dev.chromium.org/throttling for more " |
33 "information."; | 33 "information."; |
34 | 34 |
35 class HeaderFlattener : public blink::WebHTTPHeaderVisitor { | 35 class HeaderFlattener : public blink::WebHTTPHeaderVisitor { |
36 public: | 36 public: |
37 HeaderFlattener() : has_accept_header_(false) {} | 37 HeaderFlattener() {} |
38 | 38 |
39 void visitHeader(const WebString& name, const WebString& value) override { | 39 void visitHeader(const WebString& name, const WebString& value) override { |
40 // Headers are latin1. | 40 // Headers are latin1. |
41 const std::string& name_latin1 = name.latin1(); | 41 const std::string& name_latin1 = name.latin1(); |
42 const std::string& value_latin1 = value.latin1(); | 42 const std::string& value_latin1 = value.latin1(); |
43 | 43 |
44 // Skip over referrer headers found in the header map because we already | 44 // Skip over referrer headers found in the header map because we already |
45 // pulled it out as a separate parameter. | 45 // pulled it out as a separate parameter. |
46 if (base::LowerCaseEqualsASCII(name_latin1, "referer")) | 46 if (base::LowerCaseEqualsASCII(name_latin1, "referer")) |
47 return; | 47 return; |
48 | 48 |
49 if (base::LowerCaseEqualsASCII(name_latin1, "accept")) | |
50 has_accept_header_ = true; | |
51 | |
52 if (!buffer_.empty()) | 49 if (!buffer_.empty()) |
53 buffer_.append("\r\n"); | 50 buffer_.append("\r\n"); |
54 buffer_.append(name_latin1 + ": " + value_latin1); | 51 buffer_.append(name_latin1 + ": " + value_latin1); |
55 } | 52 } |
56 | 53 |
57 const std::string& GetBuffer() { | 54 const std::string& GetBuffer() { |
58 // In some cases, WebKit doesn't add an Accept header, but not having the | |
59 // header confuses some web servers. See bug 808613. | |
60 if (!has_accept_header_) { | |
61 if (!buffer_.empty()) | |
62 buffer_.append("\r\n"); | |
63 buffer_.append("Accept: */*"); | |
64 has_accept_header_ = true; | |
65 } | |
66 return buffer_; | 55 return buffer_; |
67 } | 56 } |
68 | 57 |
69 private: | 58 private: |
70 std::string buffer_; | 59 std::string buffer_; |
71 bool has_accept_header_; | |
72 }; | 60 }; |
73 | 61 |
74 } // namespace | 62 } // namespace |
75 | 63 |
76 ResourceType WebURLRequestToResourceType(const WebURLRequest& request) { | 64 ResourceType WebURLRequestToResourceType(const WebURLRequest& request) { |
77 WebURLRequest::RequestContext requestContext = request.getRequestContext(); | 65 WebURLRequest::RequestContext requestContext = request.getRequestContext(); |
78 if (request.getFrameType() != WebURLRequest::FrameTypeNone) { | 66 if (request.getFrameType() != WebURLRequest::FrameTypeNone) { |
79 DCHECK(requestContext == WebURLRequest::RequestContextForm || | 67 DCHECK(requestContext == WebURLRequest::RequestContextForm || |
80 requestContext == WebURLRequest::RequestContextFrame || | 68 requestContext == WebURLRequest::RequestContextFrame || |
81 requestContext == WebURLRequest::RequestContextHyperlink || | 69 requestContext == WebURLRequest::RequestContextHyperlink || |
(...skipping 362 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
444 bool stale_copy_in_cache, | 432 bool stale_copy_in_cache, |
445 int reason, | 433 int reason, |
446 bool was_ignored_by_handler) { | 434 bool was_ignored_by_handler) { |
447 blink::WebURLError error = | 435 blink::WebURLError error = |
448 CreateWebURLError(unreachable_url, stale_copy_in_cache, reason); | 436 CreateWebURLError(unreachable_url, stale_copy_in_cache, reason); |
449 error.wasIgnoredByHandler = was_ignored_by_handler; | 437 error.wasIgnoredByHandler = was_ignored_by_handler; |
450 return error; | 438 return error; |
451 } | 439 } |
452 | 440 |
453 } // namespace content | 441 } // namespace content |
OLD | NEW |