A Discrete-Event Network Simulator
API
http-header.h
Go to the documentation of this file.
1 /* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2020 DOTFEESA www.tk.etf.unsa.ba
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License version 2 as
7  * published by the Free Software Foundation;
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  *
18  * Author: Emir Dervisevic <emir.dervisevic@etf.unsa.ba>
19  * Miralem Mehic <miralem.mehic@ieee.org>
20  */
21 
22 #ifndef HTTP_HEADER_H
23 #define HTTP_HEADER_H
24 
25 #include <ns3/header.h>
26 #include <ns3/nstime.h>
27 #include <string>
28 
29 
30 namespace ns3 {
31 
32 class Packet;
33 
56 class HttpHeader : public Header
57 {
58 public:
60  HttpHeader ();
61 
66  static TypeId GetTypeId ();
67 
68  // Inherited from ObjectBase base class.
69  virtual TypeId GetInstanceTypeId () const;
70 
71  // Inherited from Header base class.
72  virtual uint32_t GetSerializedSize () const;
73  virtual void Serialize (Buffer::Iterator start) const;
74  virtual uint32_t Deserialize (Buffer::Iterator start);
75  virtual void Print (std::ostream &os) const;
76 
80  std::string ToString () const;
81 
84  {
85  NOT_SET = 0,
87  EMBEDDED_OBJECT = 2
88  };
89 
90  enum HttpMethod {
91  DELETE = 0,
92  GET = 1,
93  HEAD = 2,
94  PATCH = 3,
95  POST = 4,
96  PUT = 5
97  };
98 
100  {
101  Continue = 100,
103  Processing = 102,
104  EarlyHints = 103,
105 
106  Ok = 200,
107  Created = 201,
108  Accepted = 202,
110  NoContent = 204,
113  MultiStatus = 207,
115  ImUsed = 226,
116 
119  Found = 302,
120  SeeOther = 303,
121  NotModified = 304,
122  UseProxy = 305,
125 
126  BadRequest = 400,
129  Forbidden = 403,
130  NotFound = 404,
135  Conflict = 409,
136  Gone = 410,
140  UriTooLong = 414,
144  ImaTeapot = 418,
147  Locked = 423,
149  TooEarly = 425,
155 
158  BadGateway = 502,
165  NotExtended = 510,
167  };
168 
172  void SetContentType (ContentType_t contentType);
173 
177  ContentType_t GetContentType () const;
178 
182  void SetContentLength (uint32_t contentLength);
183 
187  uint32_t GetContentLength () const;
188 
192  void SetStatus (HttpStatus status);
193 
197  HttpStatus GetStatus () const;
198 
202  void SetMethod (HttpMethod method);
203 
207  HttpMethod GetMethod () const;
208 
212  void SetUri (std::string uri);
213 
217  std::string GetUri () const;
218 
223  void SetSize (uint64_t size);
224 
229  uint64_t GetSize (void) const;
230 
231 private:
232  uint16_t m_method;
233  uint16_t m_status;
234  uint16_t m_contentType;
235  uint32_t m_contentLength;
236  uint64_t m_size {0};
237  std::string m_uri;
238  std::vector <std::string> uriParams;
239 
240 }; // end of `class HttpHeader`
241 
242 
243 } // end of `namespace ns3`
244 
245 
246 #endif /* HTTP_HEADER_H */
iterator in a Buffer instance
Definition: buffer.h:100
Protocol header serialization and deserialization.
Definition: header.h:44
virtual uint32_t Deserialize(Buffer::Iterator start)=0
Deserialize the object from a buffer iterator.
Header used by web browsing applications to transmit information about content type,...
Definition: http-header.h:57
uint16_t m_method
" Connection method field in integer format.
Definition: http-header.h:232
std::string m_uri
Definition: http-header.h:237
virtual void Serialize(Buffer::Iterator start) const
Definition: http-header.cc:69
std::vector< std::string > uriParams
Definition: http-header.h:238
HttpHeader()
Creates an empty instance .
Definition: http-header.cc:33
uint16_t m_contentType
" Content type field in integer format.
Definition: http-header.h:234
virtual void Print(std::ostream &os) const
Definition: http-header.cc:121
HttpStatus GetStatus() const
Definition: http-header.cc:414
virtual TypeId GetInstanceTypeId() const
Get the most derived TypeId for this Object.
Definition: http-header.cc:54
virtual uint32_t GetSerializedSize() const
Definition: http-header.cc:60
uint64_t GetSize(void) const
Get the size information that the header is carrying.
Definition: http-header.cc:205
std::string GetUri() const
Definition: http-header.cc:681
static TypeId GetTypeId()
Returns the object TypeId.
Definition: http-header.cc:44
ContentType_t GetContentType() const
Definition: http-header.cc:162
void SetSize(uint64_t size)
Set the size information that the header will carry.
Definition: http-header.cc:199
void SetContentType(ContentType_t contentType)
Definition: http-header.cc:141
void SetContentLength(uint32_t contentLength)
Definition: http-header.cc:184
void SetStatus(HttpStatus status)
Definition: http-header.cc:211
uint16_t m_status
" Connection status field in integer format.
Definition: http-header.h:233
@ NetworkAuthenticationRequired
Definition: http-header.h:166
@ ProxyAuthenticationRequired
Definition: http-header.h:133
@ RequestHeaderFieldsTooLarge
Definition: http-header.h:153
@ NonAuthoritativeInformation
Definition: http-header.h:109
@ UnavailableForLegalReasons
Definition: http-header.h:154
HttpMethod GetMethod() const
Definition: http-header.cc:649
@ HEAD
Http Method Head.
Definition: http-header.h:93
@ DELETE
Http Method Delete.
Definition: http-header.h:91
@ PUT
Http Method Put.
Definition: http-header.h:96
@ GET
Http Method GET.
Definition: http-header.h:92
@ PATCH
Http Method Patch.
Definition: http-header.h:94
@ POST
Http Method Post.
Definition: http-header.h:95
uint32_t m_contentLength
" Content length field (in bytes unit).
Definition: http-header.h:235
uint32_t GetContentLength() const
Definition: http-header.cc:192
void SetUri(std::string uri)
Definition: http-header.cc:687
ContentType_t
The possible types of content (default = NOT_SET).
Definition: http-header.h:84
@ NOT_SET
Integer equivalent = 0.
Definition: http-header.h:85
@ MAIN_OBJECT
Integer equivalent = 1.
Definition: http-header.h:86
@ EMBEDDED_OBJECT
Integer equivalent = 2.
Definition: http-header.h:87
std::string ToString() const
Definition: http-header.cc:132
void SetMethod(HttpMethod method)
Definition: http-header.cc:617
uint64_t m_size
The 'size' information that the header is carrying.
Definition: http-header.h:236
a unique identifier for an interface.
Definition: type-id.h:59
Every class exported by the ns3 library is enclosed in the ns3 namespace.