Hybrid ICN (hICN) plugin  v21.06-rc0-4-g18fa668
message.h
1 /*
2  * Copyright (c) 2017-2020 Cisco and/or its affiliates.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at:
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #pragma once
17 
18 #ifdef _WIN32
19 #include <hicn/transport/portability/win_portability.h>
20 #endif
21 
22 #include <hicn/transport/utils/membuf.h>
23 
24 #include <map>
25 #include <sstream>
26 #include <vector>
27 
28 #define HTTP_VERSION "1.1"
29 
30 namespace transport {
31 
32 namespace http {
33 
34 typedef enum { GET, POST, PUT, PATCH, DELETE } HTTPMethod;
35 
36 static std::map<HTTPMethod, std::string> method_map = {
37  {GET, "GET"}, {POST, "POST"}, {PUT, "PUT"},
38  {PATCH, "PATCH"}, {DELETE, "DELETE"},
39 };
40 
41 typedef std::map<std::string, std::string> HTTPHeaders;
42 typedef std::unique_ptr<utils::MemBuf> HTTPPayload;
43 
44 class HTTPMessage {
45  public:
46  virtual ~HTTPMessage() = default;
47 
48  const HTTPHeaders getHeaders() { return headers_; };
49 
50  void coalescePayloadBuffer() {
51  auto it = headers_.find("Content-Length");
52  if (it != headers_.end()) {
53  auto content_length = std::stoul(it->second);
54  payload_->gather(content_length);
55  }
56  }
57 
58  HTTPPayload &&getPayload() { return std::move(payload_); }
59 
60  std::string getHttpVersion() const { return http_version_; };
61 
62  protected:
63  HTTPHeaders headers_;
64  HTTPPayload payload_;
65  std::string http_version_;
66 };
67 
68 } // end namespace http
69 
70 } // end namespace transport
transport::http::HTTPMessage
Definition: message.h:44
transport
Definition: forwarder_config.h:32