2015-10-05 01:26:43 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <sstream>
|
|
|
|
#include <Poco/Net/HTMLForm.h>
|
|
|
|
#include <Poco/Net/HTTPRequest.h>
|
|
|
|
#include <Poco/URI.h>
|
|
|
|
|
2017-02-09 10:10:13 +00:00
|
|
|
#include <DB/IO/ReadHelpers.h>
|
|
|
|
|
2015-10-05 01:26:43 +00:00
|
|
|
|
2016-06-25 07:22:12 +00:00
|
|
|
/** Somehow, in case of POST, Poco::Net::HTMLForm doesn't read parameters from URL, only from body.
|
|
|
|
* This helper allows to read parameters just from URL.
|
|
|
|
*/
|
2015-10-05 01:26:43 +00:00
|
|
|
struct HTMLForm : public Poco::Net::HTMLForm
|
|
|
|
{
|
2017-04-01 07:20:54 +00:00
|
|
|
HTMLForm(const Poco::Net::HTTPRequest & request)
|
|
|
|
{
|
|
|
|
Poco::URI uri(request.getURI());
|
|
|
|
std::istringstream istr(uri.getRawQuery());
|
|
|
|
readUrl(istr);
|
|
|
|
}
|
|
|
|
|
|
|
|
HTMLForm(const Poco::URI & uri)
|
|
|
|
{
|
|
|
|
std::istringstream istr(uri.getRawQuery());
|
|
|
|
readUrl(istr);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
T getParsed(const std::string & key, T default_value)
|
|
|
|
{
|
|
|
|
auto it = find(key);
|
|
|
|
return (it != end()) ? DB::parse<T>(it->second) : default_value;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
T getParsed(const std::string & key)
|
|
|
|
{
|
|
|
|
return DB::parse<T>(get(key));
|
|
|
|
}
|
2015-10-05 01:26:43 +00:00
|
|
|
};
|