OPeNDAP Hyrax Back End Server (BES)  Updated for version 3.8.3
RemoteHttpResource.h
Go to the documentation of this file.
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 // (c) COPYRIGHT URI/MIT 1994-1999
26 // Please read the full copyright statement in the file COPYRIGHT_URI.
27 //
28 // Authors:
29 // ndp Nathan Potter <ndp@opendap.org>
30 
31 #ifndef REMOTERESOURCE_H_
32 #define REMOTERESOURCE_H_
33 
34 
35 #include <curl/curl.h>
36 #include <curl/easy.h>
37 
38 #include "util.h"
39 #include "BESCache3.h"
40 #include "InternalErr.h"
41 #include "RCReader.h"
42 
43 using std::string;
44 using std::vector;
45 
46 namespace gateway {
47 
48 
54 private:
55 
56 
60  string d_remoteResourceUrl;
61 
65  int d_fd;
66 
67 
72  bool _initialized;
73 
74 
78  CURL *d_curl;
79 
80 
84  char d_error_buffer[CURL_ERROR_SIZE]; // A human-readable message.
85 
90  string d_type;
91 
95  string d_resourceCacheFileName;
96 
100  vector<string> *d_request_headers; // Request headers
101 
105  vector<string> *d_response_headers; // Response headers
106 
107 
112  void setType(const vector<string> *resp_hdrs );
113 
118  void writeResourceToFile(int fd);
119 
120 
121 
122 protected:
123 
125  d_fd(0),
126  d_curl(0),
127  d_response_headers(0),
128  d_request_headers(0),
129  _initialized(false),
130  d_resourceCacheFileName("")
131  {}
132 
133 
134 public:
135 
136  RemoteHttpResource(const string &url);
137  virtual ~RemoteHttpResource();
138 
139  void retrieveResource();
140 
141 
146  string getType() {
147  return d_type;
148  }
149 
154  string getCacheFileName() {
155  if(!_initialized)
156  throw libdap::Error("RemoteHttpResource::getCacheFileName() - STATE ERROR: Remote Resource Has Not Been Retrieved.");
157  return d_resourceCacheFileName;
158  }
159 
163  vector<string> *getResponseHeaders() {
164  if(!_initialized)
165  throw libdap::Error("RemoteHttpResource::getCacheFileName() - STATE ERROR: Remote Resource Has Not Been Retrieved.");
166  return d_response_headers;
167  }
168 
169 };
170 
171 } /* namespace gateway */
172 #endif /* REMOTERESOURCE_H_ */
vector< string > * getResponseHeaders()
Returns a vector of HTTP headers received along with the response from the request for the remote res...
virtual ~RemoteHttpResource()
Releases any memory resources and also any existing cache file locks for the cached resource...
string getCacheFileName()
Returns the (read-locked) cache file name on the local system in which the content of the remote reso...
This class encapsulates a remote resource available via HTTP GET.
string getType()
Returns the DAP type string of the RemoteHttpResource.
void retrieveResource()
This method will check the cache for the resource.