mirror of https://github.com/kiwix/libkiwix.git
Handle multiple arguments in RequestContext.
This commit is contained in:
parent
854623618c
commit
98c54b2279
|
@ -106,7 +106,7 @@ MHD_Result RequestContext::fill_argument(void *__this, enum MHD_ValueKind kind,
|
||||||
const char *key, const char* value)
|
const char *key, const char* value)
|
||||||
{
|
{
|
||||||
RequestContext *_this = static_cast<RequestContext*>(__this);
|
RequestContext *_this = static_cast<RequestContext*>(__this);
|
||||||
_this->arguments[key] = value == nullptr ? "" : value;
|
_this->arguments[key].push_back(value == nullptr ? "" : value);
|
||||||
return MHD_YES;
|
return MHD_YES;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -121,8 +121,14 @@ void RequestContext::print_debug_info() const {
|
||||||
printf(" - %s : '%s'\n", it->first.c_str(), it->second.c_str());
|
printf(" - %s : '%s'\n", it->first.c_str(), it->second.c_str());
|
||||||
}
|
}
|
||||||
printf("arguments :\n");
|
printf("arguments :\n");
|
||||||
for (auto it=arguments.begin(); it!=arguments.end(); it++) {
|
for (auto& pair:arguments) {
|
||||||
printf(" - %s : '%s'\n", it->first.c_str(), it->second.c_str());
|
printf(" - %s :", pair.first.c_str());
|
||||||
|
bool first = true;
|
||||||
|
for (auto& v: pair.second) {
|
||||||
|
printf("%s %s", first?"":",", v.c_str());
|
||||||
|
first = false;
|
||||||
|
}
|
||||||
|
printf("\n");
|
||||||
}
|
}
|
||||||
printf("Parsed : \n");
|
printf("Parsed : \n");
|
||||||
printf("full_url: %s\n", full_url.c_str());
|
printf("full_url: %s\n", full_url.c_str());
|
||||||
|
@ -176,7 +182,7 @@ ByteRange RequestContext::get_range() const {
|
||||||
|
|
||||||
template<>
|
template<>
|
||||||
std::string RequestContext::get_argument(const std::string& name) const {
|
std::string RequestContext::get_argument(const std::string& name) const {
|
||||||
return arguments.at(name);
|
return arguments.at(name)[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string RequestContext::get_header(const std::string& name) const {
|
std::string RequestContext::get_header(const std::string& name) const {
|
||||||
|
@ -187,8 +193,10 @@ std::string RequestContext::get_query() const {
|
||||||
std::string q;
|
std::string q;
|
||||||
const char* sep = "";
|
const char* sep = "";
|
||||||
for ( const auto& a : arguments ) {
|
for ( const auto& a : arguments ) {
|
||||||
q += sep + a.first + '=' + a.second;
|
for (const auto& v: a.second) {
|
||||||
sep = "&";
|
q += sep + a.first + '=' + v;
|
||||||
|
sep = "&";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return q;
|
return q;
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,6 +25,7 @@
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <map>
|
#include <map>
|
||||||
|
#include <vector>
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
|
|
||||||
#include "byte_range.h"
|
#include "byte_range.h"
|
||||||
|
@ -69,7 +70,11 @@ class RequestContext {
|
||||||
std::string get_header(const std::string& name) const;
|
std::string get_header(const std::string& name) const;
|
||||||
template<typename T=std::string>
|
template<typename T=std::string>
|
||||||
T get_argument(const std::string& name) const {
|
T get_argument(const std::string& name) const {
|
||||||
return extractFromString<T>(arguments.at(name));
|
return extractFromString<T>(get_argument(name));
|
||||||
|
}
|
||||||
|
|
||||||
|
std::vector<std::string> get_arguments(const std::string& name) const {
|
||||||
|
return arguments.at(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<class T>
|
template<class T>
|
||||||
|
@ -105,7 +110,7 @@ class RequestContext {
|
||||||
|
|
||||||
ByteRange byteRange_;
|
ByteRange byteRange_;
|
||||||
std::map<std::string, std::string> headers;
|
std::map<std::string, std::string> headers;
|
||||||
std::map<std::string, std::string> arguments;
|
std::map<std::string, std::vector<std::string>> arguments;
|
||||||
|
|
||||||
private: // functions
|
private: // functions
|
||||||
static MHD_Result fill_header(void *, enum MHD_ValueKind, const char*, const char*);
|
static MHD_Result fill_header(void *, enum MHD_ValueKind, const char*, const char*);
|
||||||
|
|
Loading…
Reference in New Issue