http_raw_request_headers.h 2.1 KB

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