libdap++  Updated for version 3.8.2
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 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  vector<string> *d_headers; // Response headers
63  string d_file; // Temp file that holds response body
64 
65 protected:
69  {}
71  {}
73  {
74  throw InternalErr(__FILE__, __LINE__, "Unimplemented assignment");
75  }
77 
78 public:
95  HTTPResponse(FILE *s, int status, vector<string> *h, const string &temp_file)
96  : Response(s, status), d_headers(h), d_file(temp_file)
97  {
98  DBG(cerr << "Headers: " << endl);
99  DBGN(copy(d_headers->begin(), d_headers->end(),
100  ostream_iterator<string>(cerr, "\n")));
101  DBGN(cerr << "end of headers." << endl);
102  }
103 
107  virtual ~HTTPResponse()
108  {
109  DBG(cerr << "Freeing HTTPConnect resources (" + d_file + ")... ");
110 
111  if (!dods_keep_temps && !d_file.empty()) {
112  close_temp(get_stream(), d_file);
113  set_stream(0);
114  }
115 
116  delete d_headers; d_headers = 0;
117 
118  DBGN(cerr << endl);
119  }
122  virtual vector<string> *get_headers() const
123  {
124  return d_headers;
125  }
126  virtual string get_file() const
127  {
128  return d_file;
129  }
131 
134  virtual void set_headers(vector<string> *h)
135  {
136  d_headers = h;
137  }
139 };
140 
141 } // namespace libdap
142 
143 #endif // http_response_h
virtual void set_stream(FILE *s)
Definition: Response.h:139
#define DBGN(x)
Definition: debug.h:59
virtual void set_headers(vector< string > *h)
Definition: HTTPResponse.h:134
HTTPResponse(FILE *s, int status, vector< string > *h, const string &temp_file)
Definition: HTTPResponse.h:95
A class for software fault reporting.
Definition: InternalErr.h:64
#define DBG(x)
Definition: debug.h:58
virtual FILE * get_stream() const
Definition: Response.h:115
void close_temp(FILE *s, const string &name)
Definition: HTTPConnect.cc:718
HTTPResponse(const HTTPResponse &rs)
Definition: HTTPResponse.h:70
int dods_keep_temps
Definition: HTTPConnect.cc:76
HTTPResponse & operator=(const HTTPResponse &)
Definition: HTTPResponse.h:72
virtual string get_file() const
Definition: HTTPResponse.h:126
virtual vector< string > * get_headers() const
Definition: HTTPResponse.h:122