bes Updated for version 3.21.1
The Backend Server (BES) is the lower two tiers of the Hyrax data server
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
31#include <string>
32#include <map>
33#include <vector>
34#include <memory>
35#include <chrono>
36
37namespace http {
38
44class url {
45public:
46 using kvp_map_t = std::map<std::string, std::vector<std::string>>;
47
48private:
49 std::string d_source_url_str;
50 std::string d_protocol;
51 std::string d_host;
52 std::string d_path;
53 std::string d_query;
54 kvp_map_t d_query_kvp;
55 std::chrono::system_clock::time_point d_ingest_time = std::chrono::system_clock::now();
56 bool d_trusted = false;
57
58 void parse();
59 void parse_query_string();
60
61 friend class HttpUrlTest;
62
63public:
64 url() = default;
65
66 explicit url(std::string url_s, bool trusted = false) :
67 d_source_url_str(std::move(url_s)),
68 d_trusted(trusted) {
69 parse();
70 }
71
72 url(const http::url &src_url) = default;
73
74 // TODO Remove these shared_ptr methods if possible. jhrg 2/20/25
75 explicit url(const std::shared_ptr<http::url> &source_url) :
76 d_source_url_str(source_url->d_source_url_str),
77 d_protocol(source_url->d_protocol),
78 d_host(source_url->d_host),
79 d_path(source_url->d_path),
80 d_query(source_url->d_query),
81 d_query_kvp(source_url->d_query_kvp),
82 d_ingest_time(source_url->d_ingest_time),
83 d_trusted(source_url->d_trusted) {
84 }
85
86 url(const std::shared_ptr<http::url> &source_url, bool trusted) :
87 d_source_url_str(source_url->d_source_url_str),
88 d_protocol(source_url->d_protocol),
89 d_host(source_url->d_host),
90 d_path(source_url->d_path),
91 d_query(source_url->d_query),
92 d_query_kvp(source_url->d_query_kvp),
93 d_ingest_time(source_url->d_ingest_time),
94 d_trusted(trusted) {
95 }
96
97 virtual ~url() = default;
98
99 url &operator=(const url &rhs) = delete;
100
101 virtual std::string str() const { return d_source_url_str; }
102
103 virtual std::string protocol() const { return d_protocol; }
104
105 virtual std::string host() const { return d_host; }
106
107 virtual std::string path() const { return d_path; }
108
109 virtual std::string query() const { return d_query; }
110
111 virtual std::time_t ingest_time() const {
112 return std::chrono::system_clock::to_time_t(d_ingest_time);
113 }
114
115 virtual void set_ingest_time(const std::time_t &itime) {
116 d_ingest_time = std::chrono::system_clock::from_time_t(itime);
117 }
118
119 virtual std::string query_parameter_value(const std::string &key) const;
120 virtual size_t query_parameter_values_size(const std::string &key) const;
121 virtual const std::vector<std::string> &query_parameter_values(const std::string &key) const;
122
123 virtual bool is_expired();
124 virtual bool is_trusted() const { return d_trusted; };
125
126 virtual std::string dump();
127};
128
129} // namespace http
130#endif /* _bes_http_url_HH_ */
Parse a URL into the protocol, host, path and query parts.
Definition url_impl.h:44
virtual size_t query_parameter_values_size(const std::string &key) const
Return the number of query string values for a given key .
Definition url_impl.cc:183
virtual std::string query_parameter_value(const std::string &key) const
Get the value of a query string key.
Definition url_impl.cc:167
virtual std::string dump()
Definition url_impl.cc:295
virtual const std::vector< std::string > & query_parameter_values(const std::string &key) const
Get the vector of query string values for a given key.
Definition url_impl.cc:198
virtual bool is_expired()
Definition url_impl.cc:212
utility class for the HTTP catalog module
Definition TheBESKeys.h:51