| OLD | NEW |
| 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 #include "net/ocsp/nss_ocsp.h" | 5 #include "net/ocsp/nss_ocsp.h" |
| 6 | 6 |
| 7 #include <certt.h> | 7 #include <certt.h> |
| 8 #include <certdb.h> | 8 #include <certdb.h> |
| 9 #include <ocsp.h> | 9 #include <ocsp.h> |
| 10 #include <nspr.h> | 10 #include <nspr.h> |
| (...skipping 15 matching lines...) Expand all Loading... |
| 26 #include "base/string_util.h" | 26 #include "base/string_util.h" |
| 27 #include "base/stringprintf.h" | 27 #include "base/stringprintf.h" |
| 28 #include "base/synchronization/condition_variable.h" | 28 #include "base/synchronization/condition_variable.h" |
| 29 #include "base/synchronization/lock.h" | 29 #include "base/synchronization/lock.h" |
| 30 #include "base/threading/thread_checker.h" | 30 #include "base/threading/thread_checker.h" |
| 31 #include "base/time.h" | 31 #include "base/time.h" |
| 32 #include "googleurl/src/gurl.h" | 32 #include "googleurl/src/gurl.h" |
| 33 #include "net/base/host_port_pair.h" | 33 #include "net/base/host_port_pair.h" |
| 34 #include "net/base/io_buffer.h" | 34 #include "net/base/io_buffer.h" |
| 35 #include "net/base/load_flags.h" | 35 #include "net/base/load_flags.h" |
| 36 #include "net/base/upload_data.h" | 36 #include "net/base/upload_bytes_element_reader.h" |
| 37 #include "net/base/upload_data_stream.h" |
| 37 #include "net/http/http_request_headers.h" | 38 #include "net/http/http_request_headers.h" |
| 38 #include "net/http/http_response_headers.h" | 39 #include "net/http/http_response_headers.h" |
| 39 #include "net/url_request/url_request.h" | 40 #include "net/url_request/url_request.h" |
| 40 #include "net/url_request/url_request_context.h" | 41 #include "net/url_request/url_request_context.h" |
| 41 | 42 |
| 42 namespace net { | 43 namespace net { |
| 43 | 44 |
| 44 namespace { | 45 namespace { |
| 45 | 46 |
| 46 // Protects |g_request_context|. | 47 // Protects |g_request_context|. |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 183 timeout_(timeout), | 184 timeout_(timeout), |
| 184 request_(NULL), | 185 request_(NULL), |
| 185 buffer_(new IOBuffer(kRecvBufferSize)), | 186 buffer_(new IOBuffer(kRecvBufferSize)), |
| 186 response_code_(-1), | 187 response_code_(-1), |
| 187 cv_(&lock_), | 188 cv_(&lock_), |
| 188 io_loop_(NULL), | 189 io_loop_(NULL), |
| 189 finished_(false) {} | 190 finished_(false) {} |
| 190 | 191 |
| 191 void SetPostData(const char* http_data, PRUint32 http_data_len, | 192 void SetPostData(const char* http_data, PRUint32 http_data_len, |
| 192 const char* http_content_type) { | 193 const char* http_content_type) { |
| 194 // |upload_content_| should not be modified if |request_| is active. |
| 195 DCHECK(!request_); |
| 193 upload_content_.assign(http_data, http_data_len); | 196 upload_content_.assign(http_data, http_data_len); |
| 194 upload_content_type_.assign(http_content_type); | 197 upload_content_type_.assign(http_content_type); |
| 195 } | 198 } |
| 196 | 199 |
| 197 void AddHeader(const char* http_header_name, const char* http_header_value) { | 200 void AddHeader(const char* http_header_name, const char* http_header_value) { |
| 198 extra_request_headers_.SetHeader(http_header_name, | 201 extra_request_headers_.SetHeader(http_header_name, |
| 199 http_header_value); | 202 http_header_value); |
| 200 } | 203 } |
| 201 | 204 |
| 202 void Start() { | 205 void Start() { |
| (...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 396 LOAD_DO_NOT_SEND_COOKIES); | 399 LOAD_DO_NOT_SEND_COOKIES); |
| 397 | 400 |
| 398 if (http_request_method_ == "POST") { | 401 if (http_request_method_ == "POST") { |
| 399 DCHECK(!upload_content_.empty()); | 402 DCHECK(!upload_content_.empty()); |
| 400 DCHECK(!upload_content_type_.empty()); | 403 DCHECK(!upload_content_type_.empty()); |
| 401 | 404 |
| 402 request_->set_method("POST"); | 405 request_->set_method("POST"); |
| 403 extra_request_headers_.SetHeader( | 406 extra_request_headers_.SetHeader( |
| 404 HttpRequestHeaders::kContentType, upload_content_type_); | 407 HttpRequestHeaders::kContentType, upload_content_type_); |
| 405 | 408 |
| 406 scoped_refptr<UploadData> upload_data(new UploadData()); | 409 scoped_ptr<UploadElementReader> reader(new UploadBytesElementReader( |
| 407 upload_data->AppendBytes(upload_content_.data(), upload_content_.size()); | 410 upload_content_.data(), upload_content_.size())); |
| 408 request_->set_upload(upload_data); | 411 request_->set_upload(make_scoped_ptr( |
| 412 UploadDataStream::CreateWithReader(reader.Pass(), 0))); |
| 409 } | 413 } |
| 410 if (!extra_request_headers_.IsEmpty()) | 414 if (!extra_request_headers_.IsEmpty()) |
| 411 request_->SetExtraRequestHeaders(extra_request_headers_); | 415 request_->SetExtraRequestHeaders(extra_request_headers_); |
| 412 | 416 |
| 413 request_->Start(); | 417 request_->Start(); |
| 414 AddRef(); // Release after |request_| deleted. | 418 AddRef(); // Release after |request_| deleted. |
| 415 } | 419 } |
| 416 | 420 |
| 417 GURL url_; // The URL we eventually wound up at | 421 GURL url_; // The URL we eventually wound up at |
| 418 std::string http_request_method_; | 422 std::string http_request_method_; |
| 419 base::TimeDelta timeout_; // The timeout for OCSP | 423 base::TimeDelta timeout_; // The timeout for OCSP |
| 420 URLRequest* request_; // The actual request this wraps | 424 URLRequest* request_; // The actual request this wraps |
| 421 scoped_refptr<IOBuffer> buffer_; // Read buffer | 425 scoped_refptr<IOBuffer> buffer_; // Read buffer |
| 422 HttpRequestHeaders extra_request_headers_; | 426 HttpRequestHeaders extra_request_headers_; |
| 423 std::string upload_content_; // HTTP POST payload | 427 |
| 428 // HTTP POST payload. |request_| reads bytes from this. |
| 429 std::string upload_content_; |
| 424 std::string upload_content_type_; // MIME type of POST payload | 430 std::string upload_content_type_; // MIME type of POST payload |
| 425 | 431 |
| 426 int response_code_; // HTTP status code for the request | 432 int response_code_; // HTTP status code for the request |
| 427 std::string response_content_type_; | 433 std::string response_content_type_; |
| 428 scoped_refptr<HttpResponseHeaders> response_headers_; | 434 scoped_refptr<HttpResponseHeaders> response_headers_; |
| 429 std::string data_; // Results of the request | 435 std::string data_; // Results of the request |
| 430 | 436 |
| 431 // |lock_| protects |finished_| and |io_loop_|. | 437 // |lock_| protects |finished_| and |io_loop_|. |
| 432 mutable base::Lock lock_; | 438 mutable base::Lock lock_; |
| 433 base::ConditionVariable cv_; | 439 base::ConditionVariable cv_; |
| (...skipping 525 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 959 void SetURLRequestContextForNSSHttpIO(URLRequestContext* request_context) { | 965 void SetURLRequestContextForNSSHttpIO(URLRequestContext* request_context) { |
| 960 pthread_mutex_lock(&g_request_context_lock); | 966 pthread_mutex_lock(&g_request_context_lock); |
| 961 if (request_context) { | 967 if (request_context) { |
| 962 DCHECK(!g_request_context); | 968 DCHECK(!g_request_context); |
| 963 } | 969 } |
| 964 g_request_context = request_context; | 970 g_request_context = request_context; |
| 965 pthread_mutex_unlock(&g_request_context_lock); | 971 pthread_mutex_unlock(&g_request_context_lock); |
| 966 } | 972 } |
| 967 | 973 |
| 968 } // namespace net | 974 } // namespace net |
| OLD | NEW |