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

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

Issue 2365353004: Add Content-Type header to net::ReportSender reports (Closed)
Patch Set: eroman comment Created 4 years, 2 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 | « net/url_request/report_sender.h ('k') | net/url_request/report_sender_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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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/report_sender.h" 5 #include "net/url_request/report_sender.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/stl_util.h" 9 #include "base/stl_util.h"
10 #include "net/base/elements_upload_data_stream.h" 10 #include "net/base/elements_upload_data_stream.h"
(...skipping 14 matching lines...) Expand all
25 const ErrorCallback& error_callback) 25 const ErrorCallback& error_callback)
26 : request_context_(request_context), 26 : request_context_(request_context),
27 cookies_preference_(cookies_preference), 27 cookies_preference_(cookies_preference),
28 error_callback_(error_callback) {} 28 error_callback_(error_callback) {}
29 29
30 ReportSender::~ReportSender() { 30 ReportSender::~ReportSender() {
31 // Cancel all of the uncompleted requests. 31 // Cancel all of the uncompleted requests.
32 base::STLDeleteElements(&inflight_requests_); 32 base::STLDeleteElements(&inflight_requests_);
33 } 33 }
34 34
35 void ReportSender::Send(const GURL& report_uri, const std::string& report) { 35 void ReportSender::Send(const GURL& report_uri,
36 base::StringPiece content_type,
37 base::StringPiece report) {
38 DCHECK(!content_type.empty());
36 std::unique_ptr<URLRequest> url_request = 39 std::unique_ptr<URLRequest> url_request =
37 request_context_->CreateRequest(report_uri, DEFAULT_PRIORITY, this); 40 request_context_->CreateRequest(report_uri, DEFAULT_PRIORITY, this);
38 41
39 int load_flags = 42 int load_flags =
40 LOAD_BYPASS_CACHE | LOAD_DISABLE_CACHE | LOAD_DO_NOT_SEND_AUTH_DATA; 43 LOAD_BYPASS_CACHE | LOAD_DISABLE_CACHE | LOAD_DO_NOT_SEND_AUTH_DATA;
41 if (cookies_preference_ != SEND_COOKIES) { 44 if (cookies_preference_ != SEND_COOKIES) {
42 load_flags |= LOAD_DO_NOT_SEND_COOKIES | LOAD_DO_NOT_SAVE_COOKIES; 45 load_flags |= LOAD_DO_NOT_SEND_COOKIES | LOAD_DO_NOT_SAVE_COOKIES;
43 } 46 }
44 url_request->SetLoadFlags(load_flags); 47 url_request->SetLoadFlags(load_flags);
45 48
49 HttpRequestHeaders extra_headers;
50 extra_headers.SetHeader(HttpRequestHeaders::kContentType, content_type);
51 url_request->SetExtraRequestHeaders(extra_headers);
52
46 url_request->set_method("POST"); 53 url_request->set_method("POST");
47 54
55 std::vector<char> report_data(report.begin(), report.end());
48 std::unique_ptr<UploadElementReader> reader( 56 std::unique_ptr<UploadElementReader> reader(
49 UploadOwnedBytesElementReader::CreateWithString(report)); 57 new UploadOwnedBytesElementReader(&report_data));
50 url_request->set_upload( 58 url_request->set_upload(
51 ElementsUploadDataStream::CreateWithReader(std::move(reader), 0)); 59 ElementsUploadDataStream::CreateWithReader(std::move(reader), 0));
52 60
53 URLRequest* raw_url_request = url_request.get(); 61 URLRequest* raw_url_request = url_request.get();
54 inflight_requests_.insert(url_request.release()); 62 inflight_requests_.insert(url_request.release());
55 raw_url_request->Start(); 63 raw_url_request->Start();
56 } 64 }
57 65
58 void ReportSender::SetErrorCallback(const ErrorCallback& error_callback) { 66 void ReportSender::SetErrorCallback(const ErrorCallback& error_callback) {
59 error_callback_ = error_callback; 67 error_callback_ = error_callback;
(...skipping 11 matching lines...) Expand all
71 CHECK_GT(inflight_requests_.erase(request), 0u); 79 CHECK_GT(inflight_requests_.erase(request), 0u);
72 // Clean up the request, which cancels it. 80 // Clean up the request, which cancels it.
73 delete request; 81 delete request;
74 } 82 }
75 83
76 void ReportSender::OnReadCompleted(URLRequest* request, int bytes_read) { 84 void ReportSender::OnReadCompleted(URLRequest* request, int bytes_read) {
77 NOTREACHED(); 85 NOTREACHED();
78 } 86 }
79 87
80 } // namespace net 88 } // namespace net
OLDNEW
« no previous file with comments | « net/url_request/report_sender.h ('k') | net/url_request/report_sender_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698