1 | #pragma once |
---|---|
2 | |
3 | #include <sstream> |
4 | #include <Poco/Net/HTMLForm.h> |
5 | #include <Poco/Net/HTTPRequest.h> |
6 | #include <Poco/URI.h> |
7 | |
8 | #include <IO/ReadHelpers.h> |
9 | |
10 | |
11 | /** Somehow, in case of POST, Poco::Net::HTMLForm doesn't read parameters from URL, only from body. |
12 | * This helper allows to read parameters just from URL. |
13 | */ |
14 | struct HTMLForm : public Poco::Net::HTMLForm |
15 | { |
16 | HTMLForm(const Poco::Net::HTTPRequest & request) |
17 | { |
18 | Poco::URI uri(request.getURI()); |
19 | std::istringstream istr(uri.getRawQuery()); |
20 | readUrl(istr); |
21 | } |
22 | |
23 | HTMLForm(const Poco::URI & uri) |
24 | { |
25 | std::istringstream istr(uri.getRawQuery()); |
26 | readUrl(istr); |
27 | } |
28 | |
29 | |
30 | template <typename T> |
31 | T getParsed(const std::string & key, T default_value) |
32 | { |
33 | auto it = find(key); |
34 | return (it != end()) ? DB::parse<T>(it->second) : default_value; |
35 | } |
36 | |
37 | template <typename T> |
38 | T getParsed(const std::string & key) |
39 | { |
40 | return DB::parse<T>(get(key)); |
41 | } |
42 | }; |
43 |