libdap++ Updated for version 3.8.2
|
00001 00002 // -*- mode: c++; c-basic-offset:4 -*- 00003 00004 // This file is part of libdap, A C++ implementation of the OPeNDAP Data 00005 // Access Protocol. 00006 00007 // Copyright (c) 2002,2003 OPeNDAP, Inc. 00008 // Author: James Gallagher <jgallagher@opendap.org> 00009 // 00010 // This library is free software; you can redistribute it and/or 00011 // modify it under the terms of the GNU Lesser General Public 00012 // License as published by the Free Software Foundation; either 00013 // version 2.1 of the License, or (at your option) any later version. 00014 // 00015 // This library is distributed in the hope that it will be useful, 00016 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00017 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00018 // Lesser General Public License for more details. 00019 // 00020 // You should have received a copy of the GNU Lesser General Public 00021 // License along with this library; if not, write to the Free Software 00022 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00023 // 00024 // You can contact OPeNDAP, Inc. at PO Box 112, Saunderstown, RI. 02874-0112. 00025 00026 #ifndef http_response_h 00027 #define http_response_h 00028 00029 #include <cstdio> 00030 #include <string> 00031 #include <iostream> 00032 #include <algorithm> 00033 #include <iterator> 00034 #include <vector> 00035 00036 using std::vector ; 00037 00038 #ifndef response_h 00039 #include "Response.h" 00040 #endif 00041 00042 #ifndef _debug_h 00043 #include "debug.h" 00044 #endif 00045 00046 namespace libdap 00047 { 00048 00049 extern int dods_keep_temps; // defined in HTTPConnect.cc 00050 00051 extern void close_temp(FILE *s, const string &name); 00052 00059 class HTTPResponse : public Response 00060 { 00061 private: 00062 // TODO Make this a value, not a pointer. Fix all uses and then 00063 // change code in HTTPConnect 00064 vector<string> *d_headers; // Response headers 00065 string d_file; // Temp file that holds response body 00066 00067 protected: 00070 HTTPResponse() 00071 {} 00072 HTTPResponse(const HTTPResponse &rs) : Response(rs) 00073 {} 00074 HTTPResponse &operator=(const HTTPResponse &) 00075 { 00076 throw InternalErr(__FILE__, __LINE__, "Unimplemented assignment"); 00077 } 00079 00080 public: 00097 HTTPResponse(FILE *s, int status, vector<string> *h, const string &temp_file) 00098 : Response(s, status), d_headers(h), d_file(temp_file) 00099 { 00100 DBG(cerr << "Headers: " << endl); 00101 DBGN(copy(d_headers->begin(), d_headers->end(), 00102 ostream_iterator<string>(cerr, "\n"))); 00103 DBGN(cerr << "end of headers." << endl); 00104 } 00105 00109 virtual ~HTTPResponse() 00110 { 00111 DBG(cerr << "Freeing HTTPConnect resources (" + d_file + ")... "); 00112 00113 if (!dods_keep_temps && !d_file.empty()) { 00114 close_temp(get_stream(), d_file); 00115 set_stream(0); 00116 } 00117 00118 delete d_headers; d_headers = 0; 00119 00120 DBGN(cerr << endl); 00121 } 00124 virtual vector<string> *get_headers() const 00125 { 00126 return d_headers; 00127 } 00128 virtual string get_file() const 00129 { 00130 return d_file; 00131 } 00133 00136 virtual void set_headers(vector<string> *h) 00137 { 00138 d_headers = h; 00139 } 00140 00141 virtual void set_file(const string &n) 00142 { 00143 d_file = n; 00144 } 00146 }; 00147 00148 } // namespace libdap 00149 00150 #endif // http_response_h