A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Documentation ▼
Installation
Manual
Models
Contributing
Wiki
Development ▼
API Docs
Issue Tracker
Merge Requests
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
#include <algorithm>
29
30
namespace
ns3
{
31
32
class
Packet;
33
56
class
HttpHeader :
public
Header
57
{
58
public
:
59
60
62
enum
ContentType_t
63
{
64
NOT_SET
= 0,
65
MAIN_OBJECT
= 1,
66
EMBEDDED_OBJECT
= 2
67
};
68
69
enum
HttpMethod
{
70
DELETE
= 0,
71
GET
= 1,
72
HEAD
= 2,
73
PATCH
= 3,
74
POST
= 4,
75
PUT
= 5
76
};
77
78
enum
HttpStatus
79
{
80
Continue
= 100,
81
SwitchingProtocol
= 101,
82
Processing
= 102,
83
EarlyHints
= 103,
84
85
Ok
= 200,
86
Created
= 201,
87
Accepted
= 202,
88
NonAuthoritativeInformation
= 203,
89
NoContent
= 204,
90
ResetContent
= 205,
91
PartialContent
= 206,
92
MultiStatus
= 207,
93
AlreadyReported
= 208,
94
ImUsed
= 226,
95
96
MultipleChoice
= 300,
97
MovedPermanently
= 301,
98
Found
= 302,
99
SeeOther
= 303,
100
NotModified
= 304,
101
UseProxy
= 305,
102
TemporaryRedirect
= 307,
103
PermanentRedirect
= 308,
104
105
BadRequest
= 400,
106
Unauthorized
= 401,
107
PaymentRequired
= 402,
108
Forbidden
= 403,
109
NotFound
= 404,
110
MethodNotAllowed
= 405,
111
NotAcceptable
= 406,
112
ProxyAuthenticationRequired
= 407,
113
RequestTimeout
= 408,
114
Conflict
= 409,
115
Gone
= 410,
116
LengthRequired
= 411,
117
PreconditionFailed
= 412,
118
PayloadTooLarge
= 413,
119
UriTooLong
= 414,
120
UnsupportedMediaType
= 415,
121
RangeNotSatisfiable
= 416,
122
ExpectationFailed
= 417,
123
ImaTeapot
= 418,
124
MisdirectedRequest
= 421,
125
UnprocessableEntity
= 422,
126
Locked
= 423,
127
FailedDependency
= 424,
128
TooEarly
= 425,
129
UpgradeRequired
= 426,
130
PreconditionRequired
= 428,
131
TooManyRequests
= 429,
132
RequestHeaderFieldsTooLarge
= 431,
133
UnavailableForLegalReasons
= 451,
134
135
InternalServerError
= 500,
136
NotImplemented
= 501,
137
BadGateway
= 502,
138
ServiceUnavailable
= 503,
139
GatewayTimeout
= 504,
140
HttpVersionNotSupported
= 505,
141
VariantAlsoNegotiates
= 506,
142
InsufficientStorage
= 507,
143
LoopDetected
= 508,
144
NotExtended
= 510,
145
NetworkAuthenticationRequired
= 511
146
};
147
149
HttpHeader
();
150
151
void
CreateRequest
(
152
const
std::string& url,
153
const
std::string& method,
154
const
std::map<std::string, std::string>& parameters,
155
const
std::vector<std::string>& headers = {}
156
);
157
158
void
CreateRequest
(
159
const
std::string& url,
160
const
std::string& method =
"GET"
,
161
const
std::string& body =
""
,
162
const
std::vector<std::string>& headers = {}
163
);
164
165
void
CreateRequest
(
166
const
std::string& url,
167
const
std::string& method,
168
const
std::vector<uint8_t>& body,
169
const
std::vector<std::string>& headers
170
);
171
172
void
CreateResponse
(
173
const
HttpHeader::HttpStatus
status,
174
const
std::map<std::string, std::string>& body,
175
const
std::vector<std::string>& headers = {}
176
);
177
178
void
CreateResponse
(
179
const
HttpHeader::HttpStatus
status,
180
const
std::string& body =
""
,
181
const
std::vector<std::string>& headers = {}
182
);
183
184
void
CreateResponse
(
185
const
HttpHeader::HttpStatus
status,
186
const
std::vector<uint8_t>& body,
187
const
std::vector<std::string>& headers
188
);
189
194
static
TypeId
GetTypeId
();
195
196
// Inherited from ObjectBase base class.
197
virtual
TypeId
GetInstanceTypeId
()
const
;
198
199
// Inherited from Header base class.
200
virtual
uint32_t
GetSerializedSize
()
const
;
201
virtual
void
Serialize
(
Buffer::Iterator
start
)
const
;
202
virtual
uint32_t
Deserialize
(
Buffer::Iterator
start
);
203
virtual
void
Print
(std::ostream &os)
const
;
204
208
std::string
ToString
()
const
;
209
210
std::vector<uint8_t>
GetPayload
(){
211
return
m_payload
;
212
}
213
214
std::string
GetPayloadString
(){
215
if
(
m_headers
.size() == 0 &&
m_payload
.size() == 0)
ParseResponse
();
216
std::string payload = std::string{
m_payload
.begin(),
m_payload
.end()};
217
return
payload;
218
}
219
223
uint32_t
GetSize
()
const
;
224
228
void
SetStatus
(
HttpStatus
status);
229
233
HttpStatus
GetStatus
()
const
;
234
235
std::string
GetStatusString
()
const
;
236
240
void
SetMethod
(
HttpMethod
method);
241
242
void
SetMethod
(
const
std::string&
m
);
243
247
HttpMethod
GetMethod
()
const
;
248
252
std::string
GetUri
()
const
;
256
void
SetUri
(
const
std::string& url);
257
261
std::string
GetRequestUri
()
const
;
262
263
std::string
urlEncode
(
const
std::string& str);
264
265
void
ParseResponse
();
266
267
std::string
GetHeaderString
();
268
269
void
SetHeaderString
(std::string input);
270
271
uint32_t
GetContentSize
();
272
273
uint32_t
GetHeaderSize
();
274
275
bool
IsFragmented
(){
276
return
m_fragmented
;
277
}
278
279
private
:
280
281
std::string
m_scheme
;
282
std::string
m_domain
;
283
std::string
m_path
;
284
285
std::vector<std::string>
m_headers
;
286
std::vector<uint8_t>
m_payload
;
287
std::vector<uint8_t>
m_allData
;
//headers + emptyLine + m_payload
288
289
uint16_t
m_method
;
290
uint16_t
m_status
;
291
uint16_t
m_contentType
;
292
uint32_t
m_contentLength
;
293
uint32_t
m_headerSize
;
294
295
bool
m_fragmented
;
296
297
std::string
m_uri
;
298
std::string
m_request_uri
;
299
300
};
// end of `class HttpHeader`
301
302
303
}
// end of `namespace ns3`
304
305
306
#endif
/* HTTP_HEADER_H */
ns3::Buffer::Iterator
iterator in a Buffer instance
Definition:
buffer.h:100
ns3::HttpHeader::m_method
uint16_t m_method
" Connection method field in integer format.
Definition:
http-header.h:232
ns3::HttpHeader::m_uri
std::string m_uri
Definition:
http-header.h:237
ns3::HttpHeader::m_payload
std::vector< uint8_t > m_payload
Definition:
http-header.h:286
ns3::HttpHeader::GetSize
uint32_t GetSize() const
ns3::HttpHeader::GetPayload
std::vector< uint8_t > GetPayload()
Definition:
http-header.h:210
ns3::HttpHeader::HttpHeader
HttpHeader()
Creates an empty instance .
ns3::HttpHeader::m_headers
std::vector< std::string > m_headers
Definition:
http-header.h:285
ns3::HttpHeader::m_contentType
uint16_t m_contentType
" Content type field in integer format.
Definition:
http-header.h:234
ns3::HttpHeader::m_allData
std::vector< uint8_t > m_allData
Definition:
http-header.h:287
ns3::HttpHeader::Print
virtual void Print(std::ostream &os) const
ns3::HttpHeader::m_domain
std::string m_domain
Definition:
http-header.h:282
ns3::HttpHeader::GetHeaderSize
uint32_t GetHeaderSize()
Definition:
http-header.cc:576
ns3::HttpHeader::m_headerSize
uint32_t m_headerSize
Definition:
http-header.h:293
ns3::HttpHeader::GetHeaderString
std::string GetHeaderString()
Definition:
http-header.cc:410
ns3::HttpHeader::GetRequestUri
std::string GetRequestUri() const
Definition:
http-header.cc:1282
ns3::HttpHeader::GetContentSize
uint32_t GetContentSize()
Definition:
http-header.cc:581
ns3::HttpHeader::GetUri
std::string GetUri() const
ns3::HttpHeader::m_path
std::string m_path
Definition:
http-header.h:283
ns3::HttpHeader::IsFragmented
bool IsFragmented()
Definition:
http-header.h:275
ns3::HttpHeader::CreateResponse
void CreateResponse(const HttpHeader::HttpStatus status, const std::map< std::string, std::string > &body, const std::vector< std::string > &headers={})
ns3::HttpHeader::SetStatus
void SetStatus(HttpStatus status)
ns3::HttpHeader::Deserialize
virtual uint32_t Deserialize(Buffer::Iterator start)
ns3::HttpHeader::GetInstanceTypeId
virtual TypeId GetInstanceTypeId() const
Get the most derived TypeId for this Object.
ns3::HttpHeader::m_status
uint16_t m_status
" Connection status field in integer format.
Definition:
http-header.h:233
ns3::HttpHeader::GetPayloadString
std::string GetPayloadString()
Definition:
http-header.h:214
ns3::HttpHeader::m_fragmented
bool m_fragmented
Definition:
http-header.h:295
ns3::HttpHeader::Serialize
virtual void Serialize(Buffer::Iterator start) const
ns3::HttpHeader::HttpStatus
HttpStatus
Definition:
http-header.h:100
ns3::HttpHeader::Gone
@ Gone
Definition:
http-header.h:136
ns3::HttpHeader::NotExtended
@ NotExtended
Definition:
http-header.h:165
ns3::HttpHeader::UseProxy
@ UseProxy
Definition:
http-header.h:122
ns3::HttpHeader::PreconditionRequired
@ PreconditionRequired
Definition:
http-header.h:151
ns3::HttpHeader::InternalServerError
@ InternalServerError
Definition:
http-header.h:156
ns3::HttpHeader::NetworkAuthenticationRequired
@ NetworkAuthenticationRequired
Definition:
http-header.h:166
ns3::HttpHeader::ExpectationFailed
@ ExpectationFailed
Definition:
http-header.h:143
ns3::HttpHeader::TooManyRequests
@ TooManyRequests
Definition:
http-header.h:152
ns3::HttpHeader::ImUsed
@ ImUsed
Definition:
http-header.h:115
ns3::HttpHeader::Ok
@ Ok
Definition:
http-header.h:106
ns3::HttpHeader::Found
@ Found
Definition:
http-header.h:119
ns3::HttpHeader::BadRequest
@ BadRequest
Definition:
http-header.h:126
ns3::HttpHeader::RangeNotSatisfiable
@ RangeNotSatisfiable
Definition:
http-header.h:142
ns3::HttpHeader::InsufficientStorage
@ InsufficientStorage
Definition:
http-header.h:163
ns3::HttpHeader::ProxyAuthenticationRequired
@ ProxyAuthenticationRequired
Definition:
http-header.h:133
ns3::HttpHeader::Unauthorized
@ Unauthorized
Definition:
http-header.h:127
ns3::HttpHeader::MethodNotAllowed
@ MethodNotAllowed
Definition:
http-header.h:131
ns3::HttpHeader::BadGateway
@ BadGateway
Definition:
http-header.h:158
ns3::HttpHeader::Locked
@ Locked
Definition:
http-header.h:147
ns3::HttpHeader::RequestHeaderFieldsTooLarge
@ RequestHeaderFieldsTooLarge
Definition:
http-header.h:153
ns3::HttpHeader::VariantAlsoNegotiates
@ VariantAlsoNegotiates
Definition:
http-header.h:162
ns3::HttpHeader::NotModified
@ NotModified
Definition:
http-header.h:121
ns3::HttpHeader::ResetContent
@ ResetContent
Definition:
http-header.h:111
ns3::HttpHeader::UriTooLong
@ UriTooLong
Definition:
http-header.h:140
ns3::HttpHeader::MultiStatus
@ MultiStatus
Definition:
http-header.h:113
ns3::HttpHeader::MovedPermanently
@ MovedPermanently
Definition:
http-header.h:118
ns3::HttpHeader::NoContent
@ NoContent
Definition:
http-header.h:110
ns3::HttpHeader::NonAuthoritativeInformation
@ NonAuthoritativeInformation
Definition:
http-header.h:109
ns3::HttpHeader::TooEarly
@ TooEarly
Definition:
http-header.h:149
ns3::HttpHeader::FailedDependency
@ FailedDependency
Definition:
http-header.h:148
ns3::HttpHeader::SwitchingProtocol
@ SwitchingProtocol
Definition:
http-header.h:102
ns3::HttpHeader::Accepted
@ Accepted
Definition:
http-header.h:108
ns3::HttpHeader::Created
@ Created
Definition:
http-header.h:107
ns3::HttpHeader::PayloadTooLarge
@ PayloadTooLarge
Definition:
http-header.h:139
ns3::HttpHeader::NotImplemented
@ NotImplemented
Definition:
http-header.h:157
ns3::HttpHeader::MultipleChoice
@ MultipleChoice
Definition:
http-header.h:117
ns3::HttpHeader::Forbidden
@ Forbidden
Definition:
http-header.h:129
ns3::HttpHeader::Processing
@ Processing
Definition:
http-header.h:103
ns3::HttpHeader::UnsupportedMediaType
@ UnsupportedMediaType
Definition:
http-header.h:141
ns3::HttpHeader::GatewayTimeout
@ GatewayTimeout
Definition:
http-header.h:160
ns3::HttpHeader::LengthRequired
@ LengthRequired
Definition:
http-header.h:137
ns3::HttpHeader::NotAcceptable
@ NotAcceptable
Definition:
http-header.h:132
ns3::HttpHeader::AlreadyReported
@ AlreadyReported
Definition:
http-header.h:114
ns3::HttpHeader::ServiceUnavailable
@ ServiceUnavailable
Definition:
http-header.h:159
ns3::HttpHeader::Conflict
@ Conflict
Definition:
http-header.h:135
ns3::HttpHeader::PartialContent
@ PartialContent
Definition:
http-header.h:112
ns3::HttpHeader::UnavailableForLegalReasons
@ UnavailableForLegalReasons
Definition:
http-header.h:154
ns3::HttpHeader::PreconditionFailed
@ PreconditionFailed
Definition:
http-header.h:138
ns3::HttpHeader::TemporaryRedirect
@ TemporaryRedirect
Definition:
http-header.h:123
ns3::HttpHeader::NotFound
@ NotFound
Definition:
http-header.h:130
ns3::HttpHeader::UpgradeRequired
@ UpgradeRequired
Definition:
http-header.h:150
ns3::HttpHeader::PaymentRequired
@ PaymentRequired
Definition:
http-header.h:128
ns3::HttpHeader::RequestTimeout
@ RequestTimeout
Definition:
http-header.h:134
ns3::HttpHeader::UnprocessableEntity
@ UnprocessableEntity
Definition:
http-header.h:146
ns3::HttpHeader::MisdirectedRequest
@ MisdirectedRequest
Definition:
http-header.h:145
ns3::HttpHeader::SeeOther
@ SeeOther
Definition:
http-header.h:120
ns3::HttpHeader::EarlyHints
@ EarlyHints
Definition:
http-header.h:104
ns3::HttpHeader::Continue
@ Continue
Definition:
http-header.h:101
ns3::HttpHeader::HttpVersionNotSupported
@ HttpVersionNotSupported
Definition:
http-header.h:161
ns3::HttpHeader::LoopDetected
@ LoopDetected
Definition:
http-header.h:164
ns3::HttpHeader::ImaTeapot
@ ImaTeapot
Definition:
http-header.h:144
ns3::HttpHeader::PermanentRedirect
@ PermanentRedirect
Definition:
http-header.h:124
ns3::HttpHeader::GetStatusString
std::string GetStatusString() const
Definition:
http-header.cc:999
ns3::HttpHeader::SetHeaderString
void SetHeaderString(std::string input)
Definition:
http-header.cc:421
ns3::HttpHeader::HttpMethod
HttpMethod
Definition:
http-header.h:90
ns3::HttpHeader::HEAD
@ HEAD
Http Method Head.
Definition:
http-header.h:93
ns3::HttpHeader::DELETE
@ DELETE
Http Method Delete.
Definition:
http-header.h:91
ns3::HttpHeader::PUT
@ PUT
Http Method Put.
Definition:
http-header.h:96
ns3::HttpHeader::GET
@ GET
Http Method GET.
Definition:
http-header.h:92
ns3::HttpHeader::PATCH
@ PATCH
Http Method Patch.
Definition:
http-header.h:94
ns3::HttpHeader::POST
@ POST
Http Method Post.
Definition:
http-header.h:95
ns3::HttpHeader::m_contentLength
uint32_t m_contentLength
" Content length field (in bytes unit).
Definition:
http-header.h:235
ns3::HttpHeader::GetStatus
HttpStatus GetStatus() const
ns3::HttpHeader::CreateRequest
void CreateRequest(const std::string &url, const std::string &method, const std::map< std::string, std::string > ¶meters, const std::vector< std::string > &headers={})
Definition:
http-header.cc:44
ns3::HttpHeader::m_scheme
std::string m_scheme
Definition:
http-header.h:281
ns3::HttpHeader::GetTypeId
static TypeId GetTypeId()
Returns the object TypeId.
ns3::HttpHeader::m_request_uri
std::string m_request_uri
Definition:
http-header.h:298
ns3::HttpHeader::SetUri
void SetUri(std::string uri)
Definition:
http-header.cc:687
ns3::HttpHeader::ContentType_t
ContentType_t
The possible types of content (default = NOT_SET).
Definition:
http-header.h:84
ns3::HttpHeader::NOT_SET
@ NOT_SET
Integer equivalent = 0.
Definition:
http-header.h:85
ns3::HttpHeader::MAIN_OBJECT
@ MAIN_OBJECT
Integer equivalent = 1.
Definition:
http-header.h:86
ns3::HttpHeader::EMBEDDED_OBJECT
@ EMBEDDED_OBJECT
Integer equivalent = 2.
Definition:
http-header.h:87
ns3::HttpHeader::ToString
std::string ToString() const
ns3::HttpHeader::GetSerializedSize
virtual uint32_t GetSerializedSize() const
ns3::HttpHeader::SetMethod
void SetMethod(HttpMethod method)
ns3::HttpHeader::ParseResponse
void ParseResponse()
Definition:
http-header.cc:204
ns3::HttpHeader::GetMethod
HttpMethod GetMethod() const
ns3::HttpHeader::urlEncode
std::string urlEncode(const std::string &str)
Definition:
http-header.cc:1229
ns3::TypeId
a unique identifier for an interface.
Definition:
type-id.h:59
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
two-ray-to-three-gpp-ch-calibration.start
start
Definition:
two-ray-to-three-gpp-ch-calibration.py:520
two-ray-to-three-gpp-ch-calibration.m
m
Definition:
two-ray-to-three-gpp-ch-calibration.py:591
src
applications
utils
http-header.h
Generated on Sun Mar 3 2024 17:10:53 for ns-3 by
1.9.1