1 // Copyright 2017 The Chromium Authors 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #ifndef NET_HTTP_HTTP_RAW_REQUEST_HEADERS_H_ 6 #define NET_HTTP_HTTP_RAW_REQUEST_HEADERS_H_ 7 8 #include <string> 9 #include <utility> 10 #include <vector> 11 12 #include "base/functional/callback.h" 13 #include "base/strings/string_piece.h" 14 #include "net/base/net_export.h" 15 16 namespace net { 17 18 // This contains actual headers sent to the remote party, as passed to 19 // RequestHeadersCallback associated with URLRequest. 20 // The headers come in actual wire order and include those provided by 21 // BeforeSendHeaders hooks and headers added or modified by the net stack, 22 // as well as SPDY & QUIC internal headers (':method' etc). 23 // In case of non-multiplexed HTTP, request_line also provides the first 24 // line of the HTTP request (i.e. "METHOD <url> VERSION\r\n"). 25 26 class NET_EXPORT HttpRawRequestHeaders { 27 public: 28 using HeaderPair = std::pair<std::string, std::string>; 29 using HeaderVector = std::vector<HeaderPair>; 30 31 HttpRawRequestHeaders(); 32 HttpRawRequestHeaders(HttpRawRequestHeaders&&); 33 HttpRawRequestHeaders& operator=(HttpRawRequestHeaders&&); 34 35 HttpRawRequestHeaders(const HttpRawRequestHeaders&) = delete; 36 HttpRawRequestHeaders& operator=(const HttpRawRequestHeaders&) = delete; 37 38 ~HttpRawRequestHeaders(); 39 Assign(HttpRawRequestHeaders other)40 void Assign(HttpRawRequestHeaders other) { *this = std::move(other); } 41 42 void Add(base::StringPiece key, base::StringPiece value); set_request_line(base::StringPiece line)43 void set_request_line(base::StringPiece line) { 44 request_line_ = std::string(line); 45 } 46 headers()47 const HeaderVector& headers() const { return headers_; } request_line()48 const std::string& request_line() const { return request_line_; } 49 bool FindHeaderForTest(base::StringPiece key, std::string* value) const; 50 51 private: 52 HeaderVector headers_; 53 std::string request_line_; 54 }; 55 56 // A callback of this type can be passed to 57 // URLRequest::SetRequestHeadersCallback to obtain HttpRawRequestHeaders just 58 // before these hit the socket. 59 using RequestHeadersCallback = 60 base::RepeatingCallback<void(HttpRawRequestHeaders)>; 61 62 } // namespace net 63 64 #endif // NET_HTTP_HTTP_RAW_REQUEST_HEADERS_H_ 65