mirror of https://github.com/kiwix/libkiwix.git
Use extractFromString to parse request argument.
On top of reusing code, it throw a exception if we cannot convert given argument in the type we want.
This commit is contained in:
parent
717c39f2ef
commit
f42f6a60df
|
@ -28,6 +28,7 @@
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
|
|
||||||
#include "byte_range.h"
|
#include "byte_range.h"
|
||||||
|
#include "tools/stringTools.h"
|
||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#include "microhttpd_wrapper.h"
|
#include "microhttpd_wrapper.h"
|
||||||
|
@ -68,10 +69,7 @@ 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 {
|
||||||
std::istringstream stream(arguments.at(name));
|
return extractFromString<T>(arguments.at(name));
|
||||||
T v;
|
|
||||||
stream >> v;
|
|
||||||
return v;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template<class T>
|
template<class T>
|
||||||
|
|
Loading…
Reference in New Issue