blob: 93c9726c97c10b4dcd52169b08f1618221345b30 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
|
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#pragma once
#include <vespa/vespalib/stllike/string.h>
#include <map>
namespace vespalib::portal {
class HttpRequest
{
private:
// http stuff
vespalib::string _method;
vespalib::string _uri;
vespalib::string _path;
std::map<vespalib::string, vespalib::string> _params;
vespalib::string _version;
std::map<vespalib::string, vespalib::string> _headers;
vespalib::string _host;
// internal state
vespalib::string _empty;
bool _first;
bool _done;
bool _error;
vespalib::string _header_name;
vespalib::string _line_buffer;
void set_done();
void set_error();
void handle_request_line(const vespalib::string &line);
void handle_header_line(const vespalib::string &line);
void handle_line(const vespalib::string &line);
public:
HttpRequest();
~HttpRequest();
size_t handle_data(const char *buf, size_t len);
bool need_more_data() const { return (!_error && !_done); }
bool valid() const { return (!_error && _done); }
bool is_get() const { return _method == "GET"; }
void resolve_host(const vespalib::string &my_host);
const vespalib::string &get_header(const vespalib::string &name) const;
const vespalib::string &get_host() const { return _host; }
const vespalib::string &get_uri() const { return _uri; }
const vespalib::string &get_path() const { return _path; }
bool has_param(const vespalib::string &name) const;
const vespalib::string &get_param(const vespalib::string &name) const;
std::map<vespalib::string, vespalib::string> export_params() const { return _params; }
};
} // namespace vespalib::portal
|