1
#pragma once
2

            
3
#include <memory>
4
#include <string>
5

            
6
#include "envoy/buffer/buffer.h"
7
#include "envoy/http/header_map.h"
8

            
9
namespace Envoy {
10
namespace Http {
11

            
12
/**
13
 * Wraps an HTTP message including its headers, body, and any trailers.
14
 */
15
template <class HeaderType, class TrailerType> class Message {
16
public:
17
4209
  virtual ~Message() = default;
18

            
19
  /**
20
   * @return HeaderType& the message headers.
21
   */
22
  virtual HeaderType& headers() PURE;
23

            
24
  /**
25
   * @return Buffer::Instance the message body, if any. Callers are free to modify the body.
26
   */
27
  virtual Buffer::Instance& body() PURE;
28

            
29
  /**
30
   * @return TrailerType* the message trailers, if any.
31
   */
32
  virtual TrailerType* trailers() PURE;
33

            
34
  /**
35
   * Set the trailers.
36
   * @param trailers supplies the new trailers.
37
   */
38
  virtual void trailers(std::unique_ptr<TrailerType>&& trailers) PURE;
39

            
40
  /**
41
   * @return std::string the message body as a std::string.
42
   */
43
  virtual std::string bodyAsString() const PURE;
44
};
45

            
46
using RequestMessage = Message<RequestHeaderMap, RequestTrailerMap>;
47
using RequestMessagePtr = std::unique_ptr<RequestMessage>;
48
using ResponseMessage = Message<ResponseHeaderMap, ResponseTrailerMap>;
49
using ResponseMessagePtr = std::unique_ptr<ResponseMessage>;
50

            
51
} // namespace Http
52
} // namespace Envoy