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:
Matthieu Gautier 2022-03-30 16:24:21 +02:00
parent 717c39f2ef
commit f42f6a60df
1 changed files with 2 additions and 4 deletions

View File

@ -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>