bes  Updated for version 3.20.10
EffectiveUrl.h
1 // -*- mode: c++; c-basic-offset:4 -*-
2 //
3 // EffectiveUrl.h
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 
29 #ifndef HYRAX_GIT_EFFECTIVEURL_H
30 #define HYRAX_GIT_EFFECTIVEURL_H
31 
32 #include <chrono>
33 
34 #include <memory>
35 #include <string>
36 #include <map>
37 #include <utility>
38 
39 #include "HttpNames.h"
40 #include "url_impl.h"
41 
42 namespace http {
43 
48 class EffectiveUrl : public url {
49 private:
50 
51  // We need order so we use two vectors instead of a map to hold the header "map"
52  std::vector<std::string> d_response_header_names;
53  std::vector<std::string> d_response_header_values;
54 
55  // Raw headers
56  std::vector<std::string> d_resp_hdr_lines;
57 
58 public:
59 
60  explicit EffectiveUrl();
61 
62  explicit EffectiveUrl(const std::string &url_s, bool trusted=false) : http::url(url_s,trusted), d_response_header_names(), d_response_header_values() {};
63 
64  explicit EffectiveUrl(const std::string &url_s, const std::vector<std::string> &resp_hdrs, bool trusted=false) : http::url(url_s,trusted) {
65  ingest_response_headers(resp_hdrs);
66  };
67 
72  EffectiveUrl(EffectiveUrl const &src_url) : http::url(src_url) {
73  d_response_header_values = src_url.d_response_header_values;
74  d_response_header_names = src_url.d_response_header_names;
75  d_resp_hdr_lines = src_url.d_resp_hdr_lines;
76  }
77 
82  explicit EffectiveUrl(
83  http::url const &src_url) :
84  http::url(src_url),
85  d_response_header_names(),
86  d_response_header_values() {
87  }
88 
89  explicit EffectiveUrl(const std::shared_ptr<http::EffectiveUrl> &source_url): http::url(source_url) {
90  d_response_header_values = source_url->d_response_header_values;
91  d_response_header_names = source_url->d_response_header_names;
92  d_resp_hdr_lines = source_url->d_resp_hdr_lines;
93  }
94 
95  explicit EffectiveUrl(const std::shared_ptr<http::EffectiveUrl> &source_url, bool trusted): http::url(source_url,trusted) {
96  d_response_header_values = source_url->d_response_header_values;
97  d_response_header_names = source_url->d_response_header_names;
98  d_resp_hdr_lines = source_url->d_resp_hdr_lines;
99  }
100 
101  explicit EffectiveUrl(
102  std::shared_ptr<http::url> source_url):
103  http::url(std::move(source_url)),
104  d_response_header_names(),
105  d_response_header_values()
106  {
107  }
108 
109  virtual ~EffectiveUrl(){ }
110 
111  bool is_expired() override;
112 
113  void get_header(const std::string &name, std::string &value, bool &found );
114 
115  void ingest_response_headers(const std::vector<std::string> &resp_hdrs);
116 
117  std::string dump() override;
118  };
119 } // namespace http
120 
121 #endif //HYRAX_GIT_EFFECTIVEURL_H
EffectiveUrl(http::url const &src_url)
Definition: EffectiveUrl.h:82
std::string dump() override
A string dump of the instance.
bool is_expired() override
Returns true if URL is reusable, false otherwise.
Definition: EffectiveUrl.cc:69
void get_header(const std::string &name, std::string &value, bool &found)
get the value of the named header
EffectiveUrl(EffectiveUrl const &src_url)
Definition: EffectiveUrl.h:72
void ingest_response_headers(const std::vector< std::string > &resp_hdrs)
Ingests the passed response hedaers.
utility class for the HTTP catalog module
Definition: AllowedHosts.cc:55