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

Side by Side Diff: headless/public/util/generic_url_request_job.cc

Issue 2860323002: net: add IsMethodSafe() method to HttpUtil (Closed)
Patch Set: remove IsMethodSafe() from generic_url_request_job.cc Created 3 years, 7 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
« no previous file with comments | « headless/lib/headless_browser_browsertest.cc ('k') | net/http/http_util.h » ('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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 "headless/public/util/generic_url_request_job.h" 5 #include "headless/public/util/generic_url_request_job.h"
6 6
7 #include <string.h> 7 #include <string.h>
8 #include <algorithm> 8 #include <algorithm>
9 9
10 #include "base/logging.h" 10 #include "base/logging.h"
11 #include "content/public/browser/devtools_agent_host.h" 11 #include "content/public/browser/devtools_agent_host.h"
12 #include "content/public/browser/render_frame_host.h" 12 #include "content/public/browser/render_frame_host.h"
13 #include "content/public/browser/resource_request_info.h" 13 #include "content/public/browser/resource_request_info.h"
14 #include "content/public/browser/web_contents.h" 14 #include "content/public/browser/web_contents.h"
15 #include "headless/lib/browser/headless_browser_context_impl.h" 15 #include "headless/lib/browser/headless_browser_context_impl.h"
16 #include "headless/public/headless_browser_context.h" 16 #include "headless/public/headless_browser_context.h"
17 #include "headless/public/util/url_request_dispatcher.h" 17 #include "headless/public/util/url_request_dispatcher.h"
18 #include "net/base/io_buffer.h" 18 #include "net/base/io_buffer.h"
19 #include "net/base/net_errors.h" 19 #include "net/base/net_errors.h"
20 #include "net/base/registry_controlled_domains/registry_controlled_domain.h" 20 #include "net/base/registry_controlled_domains/registry_controlled_domain.h"
21 #include "net/base/upload_bytes_element_reader.h" 21 #include "net/base/upload_bytes_element_reader.h"
22 #include "net/cookies/cookie_store.h" 22 #include "net/cookies/cookie_store.h"
23 #include "net/http/http_response_headers.h" 23 #include "net/http/http_response_headers.h"
24 #include "net/http/http_util.h"
24 #include "net/url_request/url_request_context.h" 25 #include "net/url_request/url_request_context.h"
25 26
26 namespace headless { 27 namespace headless {
27 namespace {
28
29 // True if the request method is "safe" (per section 4.2.1 of RFC 7231).
30 bool IsMethodSafe(const std::string& method) {
31 return method == "GET" || method == "HEAD" || method == "OPTIONS" ||
32 method == "TRACE";
33 }
34
35 } // namespace
36 28
37 uint64_t GenericURLRequestJob::next_request_id_ = 0; 29 uint64_t GenericURLRequestJob::next_request_id_ = 0;
38 30
39 GenericURLRequestJob::GenericURLRequestJob( 31 GenericURLRequestJob::GenericURLRequestJob(
40 net::URLRequest* request, 32 net::URLRequest* request,
41 net::NetworkDelegate* network_delegate, 33 net::NetworkDelegate* network_delegate,
42 URLRequestDispatcher* url_request_dispatcher, 34 URLRequestDispatcher* url_request_dispatcher,
43 std::unique_ptr<URLFetcher> url_fetcher, 35 std::unique_ptr<URLFetcher> url_fetcher,
44 Delegate* delegate, 36 Delegate* delegate,
45 HeadlessBrowserContext* headless_browser_context) 37 HeadlessBrowserContext* headless_browser_context)
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
84 // See net::URLRequestHttpJob::AddCookieHeaderAndStart(). 76 // See net::URLRequestHttpJob::AddCookieHeaderAndStart().
85 url::Origin requested_origin(rewritten_url); 77 url::Origin requested_origin(rewritten_url);
86 if (net::registry_controlled_domains::SameDomainOrHost( 78 if (net::registry_controlled_domains::SameDomainOrHost(
87 requested_origin, site_for_cookies, 79 requested_origin, site_for_cookies,
88 net::registry_controlled_domains::INCLUDE_PRIVATE_REGISTRIES)) { 80 net::registry_controlled_domains::INCLUDE_PRIVATE_REGISTRIES)) {
89 if (net::registry_controlled_domains::SameDomainOrHost( 81 if (net::registry_controlled_domains::SameDomainOrHost(
90 requested_origin, request_->initiator(), 82 requested_origin, request_->initiator(),
91 net::registry_controlled_domains::INCLUDE_PRIVATE_REGISTRIES)) { 83 net::registry_controlled_domains::INCLUDE_PRIVATE_REGISTRIES)) {
92 options.set_same_site_cookie_mode( 84 options.set_same_site_cookie_mode(
93 net::CookieOptions::SameSiteCookieMode::INCLUDE_STRICT_AND_LAX); 85 net::CookieOptions::SameSiteCookieMode::INCLUDE_STRICT_AND_LAX);
94 } else if (IsMethodSafe(request_->method())) { 86 } else if (net::HttpUtil::IsMethodSafe(request_->method())) {
95 options.set_same_site_cookie_mode( 87 options.set_same_site_cookie_mode(
96 net::CookieOptions::SameSiteCookieMode::INCLUDE_LAX); 88 net::CookieOptions::SameSiteCookieMode::INCLUDE_LAX);
97 } 89 }
98 } 90 }
99 91
100 cookie_store->GetCookieListWithOptionsAsync( 92 cookie_store->GetCookieListWithOptionsAsync(
101 rewritten_url, options, 93 rewritten_url, options,
102 base::Bind(&GenericURLRequestJob::OnCookiesAvailable, 94 base::Bind(&GenericURLRequestJob::OnCookiesAvailable,
103 weak_factory_.GetWeakPtr(), rewritten_url, method, 95 weak_factory_.GetWeakPtr(), rewritten_url, method,
104 done_callback)); 96 done_callback));
(...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after
349 } 341 }
350 342
351 mock_response_ = std::move(mock_response); 343 mock_response_ = std::move(mock_response);
352 344
353 OnFetchCompleteExtractHeaders(request_->url(), 345 OnFetchCompleteExtractHeaders(request_->url(),
354 mock_response_->response_data.data(), 346 mock_response_->response_data.data(),
355 mock_response_->response_data.size()); 347 mock_response_->response_data.size());
356 } 348 }
357 349
358 } // namespace headless 350 } // namespace headless
OLDNEW
« no previous file with comments | « headless/lib/headless_browser_browsertest.cc ('k') | net/http/http_util.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698