libdap++  Updated for version 3.13.3
HTTPResponse.h
Go to the documentation of this file.
1 
2 // -*- mode: c++; c-basic-offset:4 -*-
3 
4 // This file is part of libdap, A C++ implementation of the OPeNDAP Data
5 // Access Protocol.
6 
7 // Copyright (c) 2002,2003 OPeNDAP, Inc.
8 // Author: James Gallagher <jgallagher@opendap.org>
9 //
10 // This library is free software; you can redistribute it and/or
11 // modify it under the terms of the GNU Lesser General Public
12 // License as published by the Free Software Foundation; either
13 // version 2.1 of the License, or (at your option) any later version.
14 //
15 // This library is distributed in the hope that it will be useful,
16 // but WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 // Lesser General Public License for more details.
19 //
20 // You should have received a copy of the GNU Lesser General Public
21 // License along with this library; if not, write to the Free Software
22 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
23 //
24 // You can contact OPeNDAP, Inc. at PO Box 112, Saunderstown, RI. 02874-0112.
25 
26 #ifndef http_response_h
27 #define http_response_h
28 
29 #include <cstdio>
30 #include <string>
31 #include <iostream>
32 #include <algorithm>
33 #include <iterator>
34 #include <vector>
35 
36 using std::vector ;
37 
38 #ifndef response_h
39 #include "Response.h"
40 #endif
41 
42 #ifndef _debug_h
43 #include "debug.h"
44 #endif
45 
46 namespace libdap
47 {
48 
49 extern int dods_keep_temps; // defined in HTTPConnect.cc
50 
51 extern void close_temp(FILE *s, const string &name);
52 
59 class HTTPResponse : public Response
60 {
61 private:
62  // TODO Make this a value, not a pointer. Fix all uses and then
63  // change code in HTTPConnect
64  vector<string> *d_headers; // Response headers
65  string d_file; // Temp file that holds response body
66 
67 protected:
71  {}
73  {}
75  {
76  throw InternalErr(__FILE__, __LINE__, "Unimplemented assignment");
77  }
79 
80 public:
97  HTTPResponse(FILE *s, int status, vector<string> *h, const string &temp_file)
98  : Response(s, status), d_headers(h), d_file(temp_file)
99  {
100  DBG(cerr << "Headers: " << endl);
101  DBGN(copy(d_headers->begin(), d_headers->end(),
102  ostream_iterator<string>(cerr, "\n")));
103  DBGN(cerr << "end of headers." << endl);
104  }
105 
109  virtual ~HTTPResponse()
110  {
111  DBG(cerr << "Freeing HTTPConnect resources (" + d_file + ")... ");
112 
113  if (!dods_keep_temps && !d_file.empty()) {
114  close_temp(get_stream(), d_file);
115  set_stream(0);
116  }
117 
118  delete d_headers; d_headers = 0;
119 
120  DBGN(cerr << endl);
121  }
124  virtual vector<string> *get_headers() const
125  {
126  return d_headers;
127  }
128  virtual string get_file() const
129  {
130  return d_file;
131  }
133 
136  virtual void set_headers(vector<string> *h)
137  {
138  d_headers = h;
139  }
140 
141  virtual void set_file(const string &n)
142  {
143  d_file = n;
144  }
146 };
147 
148 } // namespace libdap
149 
150 #endif // http_response_h
virtual void set_stream(FILE *s)
Definition: Response.h:139
virtual void set_file(const string &n)
Definition: HTTPResponse.h:141
#define DBGN(x)
Definition: debug.h:59
virtual void set_headers(vector< string > *h)
Definition: HTTPResponse.h:136
HTTPResponse(FILE *s, int status, vector< string > *h, const string &temp_file)
Definition: HTTPResponse.h:97
A class for software fault reporting.
Definition: InternalErr.h:64
#define DBG(x)
Definition: debug.h:58
void close_temp(FILE *s, const string &name)
Definition: HTTPConnect.cc:740
HTTPResponse(const HTTPResponse &rs)
Definition: HTTPResponse.h:72
virtual string get_file() const
Definition: HTTPResponse.h:128
int dods_keep_temps
Definition: HTTPConnect.cc:77
HTTPResponse & operator=(const HTTPResponse &)
Definition: HTTPResponse.h:74
virtual vector< string > * get_headers() const
Definition: HTTPResponse.h:124
virtual FILE * get_stream() const
Definition: Response.h:115