Replaced tabs with spaces

This commit is contained in:
2020-06-17 11:54:09 +02:00
parent e4a3383b1f
commit 8a7b381d63
21 changed files with 1617 additions and 1617 deletions

View File

@ -15,12 +15,12 @@
using namespace std;
string to_cgi(string text) {
for (auto & c: text) c = (char) toupper(c);
long pos = 0;
while ((pos = text.find('-', pos + 1)) != string::npos) {
text.replace(pos, 1, 1, '_');
}
return text;
for (auto & c: text) c = (char) toupper(c);
long pos = 0;
while ((pos = text.find('-', pos + 1)) != string::npos) {
text.replace(pos, 1, 1, '_');
}
return text;
}
@ -28,33 +28,33 @@ string to_cgi(string text) {
* Default Constructor
*/
HttpHeader::HttpHeader() {
fields = fields;
fields = fields;
}
HttpHeader::HttpHeader(Socket *socket) : HttpHeader::HttpHeader() {
parse(socket);
parse(socket);
}
void HttpHeader::parse(Socket *socket) {
while (true) {
string line = socket->receiveLine();
if (line.length() == 0) {
break;
} else {
unsigned long pos = line.find(':');
if (pos == string::npos) {
throw (char *) "Malformed header";
}
string index = line.substr(0, pos);
string data = line.substr(pos + 1, line.length() - pos);
while (index[0] == ' ') index.erase(index.begin() + 0);
while (index[index.length() - 1] == ' ') index.erase(index.end() - 1);
while (data[0] == ' ') data.erase(data.begin() + 0);
while (data[data.length() - 1] == ' ') data.erase(data.end() - 1);
setField(index, data);
}
}
while (true) {
string line = socket->receiveLine();
if (line.length() == 0) {
break;
} else {
unsigned long pos = line.find(':');
if (pos == string::npos) {
throw (char *) "Malformed header";
}
string index = line.substr(0, pos);
string data = line.substr(pos + 1, line.length() - pos);
while (index[0] == ' ') index.erase(index.begin() + 0);
while (index[index.length() - 1] == ' ') index.erase(index.end() - 1);
while (data[0] == ' ') data.erase(data.begin() + 0);
while (data[data.length() - 1] == ' ') data.erase(data.end() - 1);
setField(index, data);
}
}
}
@ -62,7 +62,7 @@ void HttpHeader::parse(Socket *socket) {
* Default Destructor
*/
HttpHeader::~HttpHeader() {
fields.clear();
fields.clear();
}
@ -73,12 +73,12 @@ HttpHeader::~HttpHeader() {
* @param data The field data
*/
void HttpHeader::setField(string index, string data) {
removeField(index);
fields.insert(make_pair(index, data));
removeField(index);
fields.insert(make_pair(index, data));
}
void HttpHeader::removeField(string index) {
fields.erase(index);
fields.erase(index);
}
/**
@ -88,34 +88,34 @@ void HttpHeader::removeField(string index) {
* @return The field data
*/
string HttpHeader::getField(string index) {
auto i = fields.find(index);
if (i != fields.end()) {
return fields.at(index);
} else {
return "";
}
auto i = fields.find(index);
if (i != fields.end()) {
return fields.at(index);
} else {
return "";
}
}
bool HttpHeader::isExistingField(string index) {
auto i = fields.find(index);
return i != fields.end();
auto i = fields.find(index);
return i != fields.end();
}
string HttpHeader::toString() {
string header = "";
for (auto it = fields.begin(); it != fields.end(); it++ ) {
header += it->first + ": " + it->second + "\r\n";
}
return header;
string header = "";
for (auto it = fields.begin(); it != fields.end(); it++ ) {
header += it->first + ": " + it->second + "\r\n";
}
return header;
}
string HttpHeader::cgiExport() {
string header = "";
for (auto it = fields.begin(); it != fields.end(); it++ ) {
header += "HTTP_" + to_cgi(it->first) + "=" + cli_encode(it->second) + " ";
}
return header;
string header = "";
for (auto it = fields.begin(); it != fields.end(); it++ ) {
header += "HTTP_" + to_cgi(it->first) + "=" + cli_encode(it->second) + " ";
}
return header;
}