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

Side by Side Diff: net/url_request/url_request_http_job.cc

Issue 176032: Adding commandline option to override bans on certain port numbers through a ... (Closed) Base URL: http://src.chromium.org/svn/trunk/src/
Patch Set: '' Created 11 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 | « net/url_request/url_request_http_job.h ('k') | net/url_request/url_request_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) 2006-2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2009 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 "net/url_request/url_request_http_job.h" 5 #include "net/url_request/url_request_http_job.h"
6 6
7 #include "base/base_switches.h" 7 #include "base/base_switches.h"
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/compiler_specific.h" 9 #include "base/compiler_specific.h"
10 #include "base/file_util.h" 10 #include "base/file_util.h"
(...skipping 11 matching lines...) Expand all
22 #include "net/base/ssl_cert_request_info.h" 22 #include "net/base/ssl_cert_request_info.h"
23 #include "net/http/http_response_headers.h" 23 #include "net/http/http_response_headers.h"
24 #include "net/http/http_response_info.h" 24 #include "net/http/http_response_info.h"
25 #include "net/http/http_transaction.h" 25 #include "net/http/http_transaction.h"
26 #include "net/http/http_transaction_factory.h" 26 #include "net/http/http_transaction_factory.h"
27 #include "net/http/http_util.h" 27 #include "net/http/http_util.h"
28 #include "net/url_request/url_request.h" 28 #include "net/url_request/url_request.h"
29 #include "net/url_request/url_request_context.h" 29 #include "net/url_request/url_request_context.h"
30 #include "net/url_request/url_request_error_job.h" 30 #include "net/url_request/url_request_error_job.h"
31 31
32 // static
33 std::set<int> URLRequestHttpJob::explicitly_allowed_ports_;
34
32 // TODO(darin): make sure the port blocking code is not lost 35 // TODO(darin): make sure the port blocking code is not lost
33 36
34 // static 37 // static
35 URLRequestJob* URLRequestHttpJob::Factory(URLRequest* request, 38 URLRequestJob* URLRequestHttpJob::Factory(URLRequest* request,
36 const std::string& scheme) { 39 const std::string& scheme) {
37 DCHECK(scheme == "http" || scheme == "https"); 40 DCHECK(scheme == "http" || scheme == "https");
38 41
39 if (!net::IsPortAllowedByDefault(request->url().IntPort())) 42 int port = request->url().IntPort();
43 if (!net::IsPortAllowedByDefault(port) && !IsPortAllowedByOverride(port))
40 return new URLRequestErrorJob(request, net::ERR_UNSAFE_PORT); 44 return new URLRequestErrorJob(request, net::ERR_UNSAFE_PORT);
41 45
42 if (!request->context() || 46 if (!request->context() ||
43 !request->context()->http_transaction_factory()) { 47 !request->context()->http_transaction_factory()) {
44 NOTREACHED() << "requires a valid context"; 48 NOTREACHED() << "requires a valid context";
45 return new URLRequestErrorJob(request, net::ERR_INVALID_ARGUMENT); 49 return new URLRequestErrorJob(request, net::ERR_INVALID_ARGUMENT);
46 } 50 }
47 51
48 // We cache the value of the switch because this code path is hit on every 52 // We cache the value of the switch because this code path is hit on every
49 // network request. 53 // network request.
50 static const bool kForceHTTPS = 54 static const bool kForceHTTPS =
51 CommandLine::ForCurrentProcess()->HasSwitch(switches::kForceHTTPS); 55 CommandLine::ForCurrentProcess()->HasSwitch(switches::kForceHTTPS);
52 if (kForceHTTPS && scheme == "http" && 56 if (kForceHTTPS && scheme == "http" &&
53 request->context()->force_tls_state() && 57 request->context()->force_tls_state() &&
54 request->context()->force_tls_state()->IsEnabledForHost( 58 request->context()->force_tls_state()->IsEnabledForHost(
55 request->url().host())) 59 request->url().host()))
56 return new URLRequestErrorJob(request, net::ERR_DISALLOWED_URL_SCHEME); 60 return new URLRequestErrorJob(request, net::ERR_DISALLOWED_URL_SCHEME);
57 61
58 return new URLRequestHttpJob(request); 62 return new URLRequestHttpJob(request);
59 } 63 }
60 64
65 // static
66 void URLRequestHttpJob::SetExplicitlyAllowedPorts(
darin (slow to review) 2009/09/01 06:49:23 it seems like we'd want to allow port overrides fo
67 const std::wstring& allowed_ports) {
68 if (allowed_ports.empty())
69 return;
70
71 std::set<int> ports;
72 size_t last = 0;
73 size_t size = allowed_ports.size();
74 // The comma delimiter.
75 const std::wstring::value_type kComma = L',';
76
77 // Overflow is still possible for evil user inputs.
78 for (size_t i = 0; i <= size; ++i) {
79 // The string should be composed of only digits and commas.
80 if (i != size && !IsAsciiDigit(allowed_ports[i]) &&
81 (allowed_ports[i] != kComma))
82 return;
83 if (i == size || allowed_ports[i] == kComma) {
84 size_t length = i - last;
85 if (length > 0)
86 ports.insert(StringToInt(allowed_ports.substr(last, length)));
87 last = i + 1;
88 }
89 }
90 explicitly_allowed_ports_ = ports;
91 }
92
61 URLRequestHttpJob::URLRequestHttpJob(URLRequest* request) 93 URLRequestHttpJob::URLRequestHttpJob(URLRequest* request)
62 : URLRequestJob(request), 94 : URLRequestJob(request),
63 context_(request->context()), 95 context_(request->context()),
64 response_info_(NULL), 96 response_info_(NULL),
65 proxy_auth_state_(net::AUTH_STATE_DONT_NEED_AUTH), 97 proxy_auth_state_(net::AUTH_STATE_DONT_NEED_AUTH),
66 server_auth_state_(net::AUTH_STATE_DONT_NEED_AUTH), 98 server_auth_state_(net::AUTH_STATE_DONT_NEED_AUTH),
67 ALLOW_THIS_IN_INITIALIZER_LIST( 99 ALLOW_THIS_IN_INITIALIZER_LIST(
68 start_callback_(this, &URLRequestHttpJob::OnStartCompleted)), 100 start_callback_(this, &URLRequestHttpJob::OnStartCompleted)),
69 ALLOW_THIS_IN_INITIALIZER_LIST( 101 ALLOW_THIS_IN_INITIALIZER_LIST(
70 read_callback_(this, &URLRequestHttpJob::OnReadCompleted)), 102 read_callback_(this, &URLRequestHttpJob::OnReadCompleted)),
(...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after
338 &start_callback_); 370 &start_callback_);
339 if (rv == net::ERR_IO_PENDING) 371 if (rv == net::ERR_IO_PENDING)
340 return; 372 return;
341 373
342 // The transaction started synchronously, but we need to notify the 374 // The transaction started synchronously, but we need to notify the
343 // URLRequest delegate via the message loop. 375 // URLRequest delegate via the message loop.
344 MessageLoop::current()->PostTask(FROM_HERE, NewRunnableMethod( 376 MessageLoop::current()->PostTask(FROM_HERE, NewRunnableMethod(
345 this, &URLRequestHttpJob::OnStartCompleted, rv)); 377 this, &URLRequestHttpJob::OnStartCompleted, rv));
346 } 378 }
347 379
380 // static
381 bool URLRequestHttpJob::IsPortAllowedByOverride(int port) {
382 if (explicitly_allowed_ports().empty())
383 return false;
384
385 std::set<int>::const_iterator it =
386 std::find(explicitly_allowed_ports().begin(),
387 explicitly_allowed_ports().end(),
388 port);
389
390 return it != explicitly_allowed_ports().end();
391 }
392
348 void URLRequestHttpJob::CancelAuth() { 393 void URLRequestHttpJob::CancelAuth() {
349 // Proxy gets set first, then WWW. 394 // Proxy gets set first, then WWW.
350 if (proxy_auth_state_ == net::AUTH_STATE_NEED_AUTH) { 395 if (proxy_auth_state_ == net::AUTH_STATE_NEED_AUTH) {
351 proxy_auth_state_ = net::AUTH_STATE_CANCELED; 396 proxy_auth_state_ = net::AUTH_STATE_CANCELED;
352 } else { 397 } else {
353 DCHECK(server_auth_state_ == net::AUTH_STATE_NEED_AUTH); 398 DCHECK(server_auth_state_ == net::AUTH_STATE_NEED_AUTH);
354 server_auth_state_ = net::AUTH_STATE_CANCELED; 399 server_auth_state_ = net::AUTH_STATE_CANCELED;
355 } 400 }
356 401
357 // These will be reset in OnStartCompleted. 402 // These will be reset in OnStartCompleted.
(...skipping 356 matching lines...) Expand 10 before | Expand all | Expand 10 after
714 if (!ctx || !ctx->force_tls_state()) 759 if (!ctx || !ctx->force_tls_state())
715 return; 760 return;
716 761
717 std::string name = "X-Force-TLS"; 762 std::string name = "X-Force-TLS";
718 std::string value; 763 std::string value;
719 764
720 void* iter = NULL; 765 void* iter = NULL;
721 while (response_info_->headers->EnumerateHeader(&iter, name, &value)) 766 while (response_info_->headers->EnumerateHeader(&iter, name, &value))
722 ctx->force_tls_state()->DidReceiveHeader(request_info_.url, value); 767 ctx->force_tls_state()->DidReceiveHeader(request_info_.url, value);
723 } 768 }
OLDNEW
« no previous file with comments | « net/url_request/url_request_http_job.h ('k') | net/url_request/url_request_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698