mirror of
https://github.com/Relintai/pandemonium_engine.git
synced 2024-12-25 13:17:22 +01:00
Implement parsing cookies in the requests for the SimpleWebServer.
This commit is contained in:
parent
e7e95a677a
commit
e52a188794
@ -389,6 +389,21 @@ int HTTPParser::on_header_value(const char *at, size_t length) {
|
|||||||
_content_type = REQUEST_CONTENT_TEXT_PLAIN;
|
_content_type = REQUEST_CONTENT_TEXT_PLAIN;
|
||||||
//maybe just close the connection?
|
//maybe just close the connection?
|
||||||
}
|
}
|
||||||
|
} else if (_queued_header_field == "Cookie") {
|
||||||
|
Vector<String> cookies = s.split(";");
|
||||||
|
|
||||||
|
for (int i = 0; i < cookies.size(); ++i) {
|
||||||
|
String c = cookies[i].strip_edges();
|
||||||
|
|
||||||
|
if (c.get_slice_count("=") != 2) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
String key = c.get_slice("=", 0);
|
||||||
|
String val = c.get_slice("=", 1);
|
||||||
|
|
||||||
|
_request->add_cookie_data(key, val);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO close connection on chunked connection (for now)
|
//TODO close connection on chunked connection (for now)
|
||||||
|
@ -13,6 +13,13 @@
|
|||||||
#include "http_server_simple.h"
|
#include "http_server_simple.h"
|
||||||
|
|
||||||
String SimpleWebServerRequest::get_cookie(const String &key) {
|
String SimpleWebServerRequest::get_cookie(const String &key) {
|
||||||
|
for (int i = 0; i < _cookies.size(); ++i) {
|
||||||
|
const CookieData &d = _cookies[i];
|
||||||
|
if (d.key == key) {
|
||||||
|
return d.value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -121,6 +128,14 @@ void SimpleWebServerRequest::add_file(const String &key, const String &file_name
|
|||||||
_files.push_back(e);
|
_files.push_back(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SimpleWebServerRequest::add_cookie_data(const String &key, const String &value) {
|
||||||
|
CookieData d;
|
||||||
|
d.key = key;
|
||||||
|
d.value = value;
|
||||||
|
|
||||||
|
_cookies.push_back(d);
|
||||||
|
}
|
||||||
|
|
||||||
SimpleWebServerRequest::SimpleWebServerRequest() {
|
SimpleWebServerRequest::SimpleWebServerRequest() {
|
||||||
_server = nullptr;
|
_server = nullptr;
|
||||||
}
|
}
|
||||||
|
@ -47,6 +47,8 @@ public:
|
|||||||
|
|
||||||
void add_file(const String &key, const String &file_name, const PoolByteArray &data);
|
void add_file(const String &key, const String &file_name, const PoolByteArray &data);
|
||||||
|
|
||||||
|
void add_cookie_data(const String &key, const String &value);
|
||||||
|
|
||||||
//virtual String get_path_full() const;
|
//virtual String get_path_full() const;
|
||||||
|
|
||||||
SimpleWebServerRequest();
|
SimpleWebServerRequest();
|
||||||
@ -68,6 +70,13 @@ protected:
|
|||||||
};
|
};
|
||||||
|
|
||||||
Vector<FileEntry> _files;
|
Vector<FileEntry> _files;
|
||||||
|
|
||||||
|
struct CookieData {
|
||||||
|
String key;
|
||||||
|
String value;
|
||||||
|
};
|
||||||
|
|
||||||
|
Vector<CookieData> _cookies;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user