bes  Updated for version 3.20.6
gateway_module/RemoteHttpResource.h
1 // -*- mode: c++; c-basic-offset:4 -*-
2 
3 // This file is part of gateway_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 REMOTERESOURCE_H_
29 #define 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 gateway {
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 
84  void setType(const std::vector<std::string> *resp_hdrs);
85 
90  void writeResourceToFile(int fd);
91 
92 protected:
94  d_fd(0), d_initialized(false), d_curl(0), d_resourceCacheFileName(""), d_request_headers(0), d_response_headers(
95  0)
96  {
97  }
98 
99 public:
100  RemoteHttpResource(const std::string &url);
101  virtual ~RemoteHttpResource();
102 
103  void retrieveResource();
104 
109  std::string getType()
110  {
111  return d_type;
112  }
113 
118  std::string getCacheFileName()
119  {
120  if (!d_initialized)
121  throw libdap::Error(
122  "RemoteHttpResource::getCacheFileName() - STATE ERROR: Remote Resource Has Not Been Retrieved.");
123  return d_resourceCacheFileName;
124  }
125 
129  std::vector<std::string> *getResponseHeaders()
130  {
131  if (!d_initialized)
132  throw libdap::Error(
133  "RemoteHttpResource::getCacheFileName() - STATE ERROR: Remote Resource Has Not Been Retrieved.");
134  return d_response_headers;
135  }
136 
137 };
138 
139 } /* namespace gateway */
140 
141 #endif /* REMOTERESOURCE_H_ */
gateway::RemoteHttpResource::getResponseHeaders
std::vector< std::string > * getResponseHeaders()
Definition: gateway_module/RemoteHttpResource.h:129
gateway::RemoteHttpResource::getType
std::string getType()
Definition: gateway_module/RemoteHttpResource.h:109
gateway::RemoteHttpResource::~RemoteHttpResource
virtual ~RemoteHttpResource()
Definition: gateway_module/RemoteHttpResource.cc:86
gateway::RemoteHttpResource::retrieveResource
void retrieveResource()
Definition: gateway_module/RemoteHttpResource.cc:124
gateway::RemoteHttpResource
Definition: gateway_module/RemoteHttpResource.h:49
gateway::RemoteHttpResource::getCacheFileName
std::string getCacheFileName()
Definition: gateway_module/RemoteHttpResource.h:118