Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Latest commit

 

History

History
History
90 lines (70 loc) · 1.73 KB

File metadata and controls

90 lines (70 loc) · 1.73 KB
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
/*
* HTTPRequest.cpp
*
* Created on: Dec 13, 2017
* Author: frank
*/
#include "HTTPRequest.hpp"
namespace httpsserver {
HTTPRequest::HTTPRequest(ConnectionContext * con, HTTPHeaders * headers, ResourceParameters * params):
_con(con),
_headers(headers),
_params(params) {
HTTPHeader * contentLength = headers->get("Content-Length");
if (contentLength == NULL) {
_remainingContent = 0;
_contentLengthSet = false;
} else {
_remainingContent = parseInt(contentLength->_value);
_contentLengthSet = true;
}
}
HTTPRequest::~HTTPRequest() {
}
ResourceParameters * HTTPRequest::getParams() {
return _params;
}
std::string HTTPRequest::getHeader(std::string name) {
HTTPHeader * h = _headers->get(name);
if (h != NULL) {
return h->_value;
} else {
return std::string();
}
}
size_t HTTPRequest::readBytes(byte * buffer, size_t length) {
// Limit reading to content length
if (_contentLengthSet && length > _remainingContent) {
length = _remainingContent;
}
size_t bytesRead = _con->readBuffer(buffer, length);
if (_contentLengthSet) {
_remainingContent -= bytesRead;
}
return bytesRead;
}
size_t HTTPRequest::readChars(char * buffer, size_t length) {
return readBytes((byte*)buffer, length);
}
size_t HTTPRequest::getContentLength() {
return _remainingContent;
}
bool HTTPRequest::requestComplete() {
if (_contentLengthSet) {
// If we have a content size, rely on it.
return (_remainingContent == 0);
} else {
// If there is no more input...
return (_con->pendingBufferSize() == 0);
}
}
/**
* This function will drop whatever is remaining of the request body
*/
void HTTPRequest::discardRequestBody() {
byte buf[16];
while(!requestComplete()) {
readBytes(buf, 16);
}
}
} /* namespace httpsserver */
Morty Proxy This is a proxified and sanitized view of the page, visit original site.