Skip to content

Commit 5f4313e

Browse files
author
Sebastiano Merlino
committed
Added querystring to request attributes
1 parent 0bac5ce commit 5f4313e

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

src/httpserver/http_request.hpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,14 @@ class http_request
355355
{
356356
result = this->content;
357357
}
358+
const std::string get_querystring() const
359+
{
360+
return this->querystring;
361+
}
362+
void get_querystring(std::string& result) const
363+
{
364+
result = this->querystring;
365+
}
358366
/**
359367
* Method used to get the version of the request.
360368
* @return the version in string representation
@@ -411,6 +419,7 @@ class http_request
411419
footers(b.footers),
412420
cookies(b.cookies),
413421
args(b.args),
422+
querystring(b.querystring),
414423
content(b.content),
415424
version(b.version),
416425
requestor(b.requestor),
@@ -427,6 +436,7 @@ class http_request
427436
std::map<std::string, std::string, header_comparator> footers;
428437
std::map<std::string, std::string, header_comparator> cookies;
429438
std::map<std::string, std::string, arg_comparator> args;
439+
std::string querystring;
430440
std::string content;
431441
std::string version;
432442
std::string requestor;

src/webserver.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -645,6 +645,19 @@ int webserver::build_request_footer (void *cls, enum MHD_ValueKind kind, const c
645645
int webserver::build_request_args (void *cls, enum MHD_ValueKind kind, const char *key, const char *value)
646646
{
647647
modded_request* mr = static_cast<modded_request*>(cls);
648+
{
649+
char buf[strlen(key) + strlen(value) + 3];
650+
if(mr->dhr->querystring == "")
651+
{
652+
snprintf(buf, sizeof buf, "?%s=%s", key, value);
653+
mr->dhr->querystring = buf;
654+
}
655+
else
656+
{
657+
snprintf(buf, sizeof buf, "&%s=%s", key, value);
658+
mr->dhr->querystring += string(buf);
659+
}
660+
}
648661
int size = internal_unescaper((void*) mr->ws, (char*) value);
649662
mr->dhr->set_arg(key, string(value, size));
650663
return MHD_YES;

0 commit comments

Comments
 (0)