bes  Updated for version 3.20.6
cmr_module/RemoteHttpResource.h
1 // -*- mode: c++; c-basic-offset:4 -*-
2 
3 // This file is part of cmr_module, A C++ module that can be loaded in to
4 // the OPeNDAP Back-End Server (BES) and is able to handle remote requests.
5 
6 // Copyright (c) 2013 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 CMR_REMOTERESOURCE_H_
29 #define CMR_REMOTERESOURCE_H_
30 
31 #include <curl/curl.h>
32 #include <curl/easy.h>
33 
34 #include <string>
35 #include <vector>
36 
37 //#include "util.h"
38 #include "InternalErr.h"
39 #include "RCReader.h"
40 
41 namespace cmr {
42 
50 private:
52  std::string d_remoteResourceUrl;
53 
57  int d_fd;
58 
60  bool d_initialized;
61 
63  CURL *d_curl;
64 
66  char d_error_buffer[CURL_ERROR_SIZE]; // A human-readable message.
67 
69  std::string d_type;
70 
72  std::string d_resourceCacheFileName;
73 
75  std::vector<std::string> *d_request_headers; // Request headers
76 
78  std::vector<std::string> *d_response_headers; // Response headers
79 
81  std::map<std::string,std::string> *d_http_response_headers; // Response headers
82 
87  void writeResourceToFile(int fd);
88 
93  void ingest_http_headers_and_type();
94 
95 protected:
97  d_fd(0), d_initialized(false), d_curl(0), d_resourceCacheFileName(""), d_request_headers(0), d_response_headers(
98  0), d_http_response_headers(0)
99  {
100  }
101 
102 public:
103  RemoteHttpResource(const std::string &url);
104  virtual ~RemoteHttpResource();
105 
106  void retrieveResource();
107 
112  std::string getType()
113  {
114  return d_type;
115  }
116 
121  std::string getCacheFileName()
122  {
123  if (!d_initialized)
124  throw libdap::Error(
125  "RemoteHttpResource::getCacheFileName() - STATE ERROR: Remote Resource Has Not Been Retrieved.");
126  return d_resourceCacheFileName;
127  }
128 
129  std::string get_http_response_header(const std::string header_name);
130 
131 
135  std::vector<std::string> *getResponseHeaders()
136  {
137  if (!d_initialized)
138  throw libdap::Error(
139  "RemoteHttpResource::getCacheFileName() - STATE ERROR: Remote Resource Has Not Been Retrieved.");
140  return d_response_headers;
141  }
142 
143 
144 };
145 
146 } /* namespace cmr */
147 
148 #endif /* CMR_REMOTERESOURCE_H_ */
cmr::RemoteHttpResource::getType
std::string getType()
Definition: cmr_module/RemoteHttpResource.h:112
cmr::RemoteHttpResource
Definition: cmr_module/RemoteHttpResource.h:49
cmr::RemoteHttpResource::getResponseHeaders
std::vector< std::string > * getResponseHeaders()
Definition: cmr_module/RemoteHttpResource.h:135
cmr::RemoteHttpResource::getCacheFileName
std::string getCacheFileName()
Definition: cmr_module/RemoteHttpResource.h:121
cmr::RemoteHttpResource::get_http_response_header
std::string get_http_response_header(const std::string header_name)
Definition: cmr_module/RemoteHttpResource.cc:384
cmr::RemoteHttpResource::retrieveResource
void retrieveResource()
Definition: cmr_module/RemoteHttpResource.cc:130
cmr::RemoteHttpResource::~RemoteHttpResource
virtual ~RemoteHttpResource()
Definition: cmr_module/RemoteHttpResource.cc:92