bes  Updated for version 3.20.10
RemoteResource.h
1 // -*- mode: c++; c-basic-offset:4 -*-
2 
3 // This file is part of the BES http package, part of the Hyrax data server.
4 
5 // Copyright (c) 2020 OPeNDAP, Inc.
6 // Author: Nathan Potter <ndp@opendap.org>
7 //
8 // This library is free software; you can redistribute it and/or
9 // modify it under the terms of the GNU Lesser General Public
10 // License as published by the Free Software Foundation; either
11 // version 2.1 of the License, or (at your option) any later version.
12 //
13 // This library is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 // Lesser General Public License for more details.
17 //
18 // You should have received a copy of the GNU Lesser General Public
19 // License along with this library; if not, write to the Free Software
20 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 //
22 // You can contact OPeNDAP, Inc. at PO Box 112, Saunderstown, RI. 02874-0112.
23 
24 // Authors:
25 // ndp Nathan Potter <ndp@opendap.org>
26 
27 #ifndef _bes_http_REMOTE_HTTP_RESOURCE_H_
28 #define _bes_http_REMOTE_HTTP_RESOURCE_H_ 1
29 
30 #include <curl/curl.h>
31 #include <curl/easy.h>
32 
33 #include <memory>
34 #include <string>
35 #include <vector>
36 
37 #if 0
38 #include <libdap/InternalErr.h>
39 #include <libdap/RCReader.h>
40 #endif
41 
42 #include "url_impl.h"
43 #include "RemoteResource.h"
44 #include "rapidjson/document.h"
45 #include "HttpCache.h"
46 
47 namespace http {
48 
56  private:
57  friend class RemoteResourceTest;
59  // std::string d_remoteResourceUrl;
60  std::shared_ptr<http::url> d_remoteResourceUrl;
61 
63  int d_fd;
64 
66  bool d_initialized;
67 
69  std::string d_uid;
70 
72  std::string d_type;
73 
75  std::string d_resourceCacheFileName;
76 
78  // std::vector<std::string> d_request_headers; // Request headers not used, maybe later
79 
81  std::vector<std::string> *d_response_headers; // Response headers
82 
84  std::map<std::string, std::string> *d_http_response_headers; // Response headers
85 
87  long long d_expires_interval;
88 
89 #if 0
90  // FIXME Not impl. jhrg 8/7/20
95  void setType(const std::vector<std::string> *resp_hdrs);
96 #endif
101  void writeResourceToFile(int fd);
102 
107  void ingest_http_headers_and_type();
108 
119  void filter_retrieved_resource(const std::map<std::string, std::string> &content_filters);
120 
125  bool cached_resource_is_expired();
126 
130  void update_file_and_headers();
131 
137  void update_file_and_headers(const std::map<std::string, std::string> &content_filters);
138 
142  void load_hdrs_from_file();
143 
144  protected:
145  RemoteResource() :
146  d_remoteResourceUrl(), d_fd(0), d_initialized(false), d_resourceCacheFileName(""),
147  d_response_headers(0), d_http_response_headers(0), d_expires_interval(HttpCache::getCacheExpiresTime()) {
148  }
149 
150  public:
151  // RemoteResource(const std::string &url, const std::string &uid = "", const std::string &echo_token = "");
152  //RemoteResource(const std::string &url, const std::string &uid = "", long long expires_interval = HttpCache::getCacheExpiresTime());
153 
154  RemoteResource(std::shared_ptr<http::url> target_url, const std::string &uid = "", long long expires_interval = HttpCache::getCacheExpiresTime());
155 
156  virtual ~RemoteResource();
157 
158  void retrieveResource();
159  void retrieveResource(const std::map<std::string, std::string> &content_filters);
160 
165  std::string getType() {
166  return d_type;
167  }
168 
173  std::string getCacheFileName();
174 
175  std::string get_http_response_header(const std::string header_name);
176 
177 
181  std::vector<std::string> *getResponseHeaders();
182 
183 
187  std::string get_response_as_string();
188 
190 
191  };
192 
193 } /* namespace http */
194 
195 #endif /* _bes_http_REMOTE_HTTP_RESOURCE_H_ */
std::string get_response_as_string()
std::string getCacheFileName()
std::string get_http_response_header(const std::string header_name)
std::vector< std::string > * getResponseHeaders()
rapidjson::Document get_as_json()
get_as_json() This function returns the cached resource parsed into a JSON document.
std::string getType()
GenericDocument< UTF8<> > Document
GenericDocument with UTF8 encoding.
Definition: document.h:2585
utility class for the HTTP catalog module
Definition: AllowedHosts.cc:55