bes  Updated for version 3.20.8
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 <string>
34 #include <vector>
35 #if 0
36 #include "InternalErr.h"
37 #include "RCReader.h"
38 #endif
39 #include "RemoteResource.h"
40 #include "rapidjson/document.h"
41 
42 namespace http {
43 
51  private:
53  std::string d_remoteResourceUrl;
54 
58  int d_fd;
59 
61  bool d_initialized;
62 
64  std::string d_uid;
65 
67  std::string d_type;
68 
70  std::string d_resourceCacheFileName;
71 
73  // std::vector<std::string> d_request_headers; // Request headers not used, maybe later
74 
76  std::vector<std::string> *d_response_headers; // Response headers
77 
79  std::map<std::string, std::string> *d_http_response_headers; // Response headers
80 
81 #if 0
82  // FIXME Not impl. jhrg 8/7/20
87  void setType(const std::vector<std::string> *resp_hdrs);
88 #endif
93  void writeResourceToFile(int fd);
94 
99  void ingest_http_headers_and_type();
100 
111  unsigned int filter_retrieved_resource(const std::string &template_str, const std::string &update_str);
112 
113  protected:
114  RemoteResource() :
115  d_fd(0), d_initialized(false), d_resourceCacheFileName(""),
116  d_response_headers(0), d_http_response_headers(0) {
117  }
118 
119  public:
120  // RemoteResource(const std::string &url, const std::string &uid = "", const std::string &echo_token = "");
121  RemoteResource(const std::string &url, const std::string &uid = "");
122 
123  virtual ~RemoteResource();
124 
125  void retrieveResource();
126 
127  void retrieveResource(const std::string &template_key, const std::string &replace_value);
128 
133  std::string getType() {
134  return d_type;
135  }
136 
141  std::string getCacheFileName();
142 
143  std::string get_http_response_header(const std::string header_name);
144 
145 
149  std::vector<std::string> *getResponseHeaders();
150 
151 
155  std::string get_response_as_string();
156 
158 
159  };
160 
161 } /* namespace http */
162 
163 #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: EffectiveUrl.cc:58