bes Updated for version 3.20.13
url_impl.h
1
2// -*- mode: c++; c-basic-offset:4 -*-
3
4// This file is part of the BES http package, part of the Hyrax data server.
5
6// Copyright (c) 2020 OPeNDAP, Inc.
7// Author: Nathan Potter <ndp@opendap.org>
8//
9// This library is free software; you can redistribute it and/or
10// modify it under the terms of the GNU Lesser General Public
11// License as published by the Free Software Foundation; either
12// version 2.1 of the License, or (at your option) any later version.
13//
14// This library is distributed in the hope that it will be useful,
15// but WITHOUT ANY WARRANTY; without even the implied warranty of
16// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17// Lesser General Public License for more details.
18//
19// You should have received a copy of the GNU Lesser General Public
20// License along with this library; if not, write to the Free Software
21// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22//
23// You can contact OPeNDAP, Inc. at PO Box 112, Saunderstown, RI. 02874-0112.
24
25// Authors:
26// ndp Nathan Potter <ndp@opendap.org>
27
28#ifndef _bes_http_url_HH_
29#define _bes_http_url_HH_ 1
30#include <string>
31#include <map>
32#include <vector>
33#include <memory>
34#include <chrono>
35
36namespace http {
37
38class EffectiveUrlCache;
39
40class url {
41private:
42
43 std::string d_source_url_str;
44 std::string d_protocol;
45 std::string d_host;
46 std::string d_path;
47 std::string d_query;
48 std::map<std::string, std::vector<std::string> * > d_query_kvp;
49 // time_t d_ingest_time;
50 std::chrono::system_clock::time_point d_ingest_time;
51 bool d_trusted;
52
53 void parse();
54
55protected:
56
57
58public:
59
60 explicit url() :
61 d_source_url_str(""),
62 d_protocol(""),
63 d_host(""),
64 d_path(""),
65 d_query(""),
66 d_ingest_time(std::chrono::system_clock::now()),
67 d_trusted(false) {
68 }
69 explicit url(const std::string &url_s, bool trusted=false) :
70 d_source_url_str(url_s),
71 d_protocol(""),
72 d_host(""),
73 d_path(""),
74 d_query(""),
75 d_ingest_time(std::chrono::system_clock::now()),
76 d_trusted(trusted) {
77 parse();
78 }
79
80 url(http::url const &src_url){
81 d_source_url_str = src_url.d_source_url_str;
82 d_protocol = src_url.d_protocol;
83 d_host = src_url.d_host;
84 d_path = src_url.d_path;
85 d_query = src_url.d_query;
86 d_ingest_time = src_url.d_ingest_time;
87 d_trusted = src_url.d_trusted;
88 }
89
90 explicit url(const std::shared_ptr<http::url> &source_url){
91 d_source_url_str = source_url->d_source_url_str;
92 d_protocol = source_url->d_protocol;
93 d_host = source_url->d_host;
94 d_path = source_url->d_path;
95 d_query = source_url->d_query;
96 d_ingest_time = source_url->d_ingest_time;
97 d_trusted = source_url->d_trusted;
98 }
99
100 explicit url(const std::shared_ptr<http::url> &source_url, bool trusted){
101 d_source_url_str = source_url->d_source_url_str;
102 d_protocol = source_url->d_protocol;
103 d_host = source_url->d_host;
104 d_path = source_url->d_path;
105 d_query = source_url->d_query;
106 d_ingest_time = source_url->d_ingest_time;
107 d_trusted = trusted;
108 }
109
110 virtual ~url();
111
112 virtual std::string str() const { return d_source_url_str; }
113
114 virtual std::string protocol() const { return d_protocol; }
115
116 virtual std::string host() const { return d_host; }
117
118 virtual std::string path() const { return d_path; }
119
120 virtual std::string query() const { return d_query; }
121
122 virtual std::time_t ingest_time() const {
123 return std::chrono::system_clock::to_time_t(d_ingest_time);
124 }
125
126 virtual void set_ingest_time(const std::time_t &itime){
127 d_ingest_time = std::chrono::system_clock::from_time_t(itime);
128 }
129
130 virtual std::string query_parameter_value(const std::string &key) const;
131 virtual void query_parameter_values(const std::string &key, std::vector<std::string> &values) const;
132
133 virtual bool is_expired();
134 virtual bool is_trusted() { return d_trusted; };
135
136 virtual std::string dump();
137
138};
139
140} // namespace http
141#endif /* _bes_http_url_HH_ */
virtual void query_parameter_values(const std::string &key, std::vector< std::string > &values) const
Definition: url_impl.cc:270
virtual std::string query_parameter_value(const std::string &key) const
Definition: url_impl.cc:251
virtual std::string dump()
Definition: url_impl.cc:397
virtual bool is_expired()
Definition: url_impl.cc:311
utility class for the HTTP catalog module
Definition: AllowedHosts.cc:55