blob: 28f6fbf43cb6e57e94cb1f4fb2690e5564263358 [file] [log] [blame]
Andrey Kosyakov83a6eee2017-08-14 19:20:041// 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
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/callback.h"
13#include "base/macros.h"
14#include "base/strings/string_piece.h"
15#include "net/base/net_export.h"
16
17namespace net {
18
19// This contains actual headers sent to the remote party, as passed to
20// RequestHeadersCallback associated with URLRequest.
21// The headers come in actual wire order and include those provided by
22// BeforeSendHeaders hooks and headers added or modified by the net stack,
23// as well as SPDY & QUIC internal headers (':method' etc).
24// In case of non-multiplexed HTTP, request_line also provides the first
25// line of the HTTP request (i.e. "METHOD <url> VERSION\r\n").
26
27class NET_EXPORT HttpRawRequestHeaders {
28 public:
29 using HeaderPair = std::pair<std::string, std::string>;
30 using HeaderVector = std::vector<HeaderPair>;
31
32 HttpRawRequestHeaders();
33 HttpRawRequestHeaders(HttpRawRequestHeaders&&);
34 HttpRawRequestHeaders& operator=(HttpRawRequestHeaders&&);
35 ~HttpRawRequestHeaders();
36
37 void Assign(HttpRawRequestHeaders other) { *this = std::move(other); }
38
39 void Add(base::StringPiece key, base::StringPiece value);
40 void set_request_line(base::StringPiece line) {
41 request_line_ = line.as_string();
42 }
43
44 const HeaderVector& headers() const { return headers_; }
45 const std::string& request_line() const { return request_line_; }
46 bool FindHeaderForTest(base::StringPiece key, std::string* value) const;
47
48 private:
49 HeaderVector headers_;
50 std::string request_line_;
51
52 DISALLOW_COPY_AND_ASSIGN(HttpRawRequestHeaders);
53};
54
55// A callback of this type can be passed to
56// URLRequest::SetRequestHeadersCallback to obtain HttpRawRequestHeaders just
57// before these hit the socket.
58using RequestHeadersCallback =
59 base::RepeatingCallback<void(HttpRawRequestHeaders)>;
60
61} // namespace net
62
63#endif // NET_HTTP_HTTP_RAW_REQUEST_HEADERS_H_