|
Packit |
a4aae4 |
|
|
Packit |
a4aae4 |
// -*- mode: c++; c-basic-offset:4 -*-
|
|
Packit |
a4aae4 |
|
|
Packit |
a4aae4 |
// This file is part of libdap, A C++ implementation of the OPeNDAP Data
|
|
Packit |
a4aae4 |
// Access Protocol.
|
|
Packit |
a4aae4 |
|
|
Packit |
a4aae4 |
// Copyright (c) 2002,2003 OPeNDAP, Inc.
|
|
Packit |
a4aae4 |
// Author: James Gallagher <jgallagher@opendap.org>
|
|
Packit |
a4aae4 |
//
|
|
Packit |
a4aae4 |
// This library is free software; you can redistribute it and/or
|
|
Packit |
a4aae4 |
// modify it under the terms of the GNU Lesser General Public
|
|
Packit |
a4aae4 |
// License as published by the Free Software Foundation; either
|
|
Packit |
a4aae4 |
// version 2.1 of the License, or (at your option) any later version.
|
|
Packit |
a4aae4 |
//
|
|
Packit |
a4aae4 |
// This library is distributed in the hope that it will be useful,
|
|
Packit |
a4aae4 |
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit |
a4aae4 |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
Packit |
a4aae4 |
// Lesser General Public License for more details.
|
|
Packit |
a4aae4 |
//
|
|
Packit |
a4aae4 |
// You should have received a copy of the GNU Lesser General Public
|
|
Packit |
a4aae4 |
// License along with this library; if not, write to the Free Software
|
|
Packit |
a4aae4 |
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
Packit |
a4aae4 |
//
|
|
Packit |
a4aae4 |
// You can contact OPeNDAP, Inc. at PO Box 112, Saunderstown, RI. 02874-0112.
|
|
Packit |
a4aae4 |
|
|
Packit |
a4aae4 |
#ifndef cache_http_response_h
|
|
Packit |
a4aae4 |
#define cache_http_response_h
|
|
Packit |
a4aae4 |
|
|
Packit |
a4aae4 |
#include <cstdio>
|
|
Packit |
a4aae4 |
|
|
Packit |
a4aae4 |
#ifndef response_h
|
|
Packit |
a4aae4 |
#include "Response.h"
|
|
Packit |
a4aae4 |
#endif
|
|
Packit |
a4aae4 |
|
|
Packit |
a4aae4 |
#ifndef _debug_h
|
|
Packit |
a4aae4 |
#include "debug.h"
|
|
Packit |
a4aae4 |
#endif
|
|
Packit |
a4aae4 |
|
|
Packit |
a4aae4 |
namespace libdap
|
|
Packit |
a4aae4 |
{
|
|
Packit |
a4aae4 |
|
|
Packit |
a4aae4 |
/** Encapsulate a response. Instead of directly returning the FILE pointer
|
|
Packit |
a4aae4 |
from which a response is read, return an instance of this object. */
|
|
Packit |
a4aae4 |
class HTTPCacheResponse : public HTTPResponse
|
|
Packit |
a4aae4 |
{
|
|
Packit |
a4aae4 |
private:
|
|
Packit |
a4aae4 |
HTTPCache *d_cache; // pointer to singleton instance
|
|
Packit |
a4aae4 |
|
|
Packit |
a4aae4 |
protected:
|
|
Packit |
a4aae4 |
/** @name Suppressed default methods */
|
|
Packit |
a4aae4 |
//@{
|
|
Packit |
a4aae4 |
HTTPCacheResponse();
|
|
Packit |
a4aae4 |
HTTPCacheResponse(const HTTPCacheResponse &rs);
|
|
Packit |
a4aae4 |
HTTPCacheResponse &operator=(const HTTPCacheResponse &);
|
|
Packit |
a4aae4 |
//@}
|
|
Packit |
a4aae4 |
|
|
Packit |
a4aae4 |
public:
|
|
Packit |
a4aae4 |
/** Build a Response object. Instances of this class are used to
|
|
Packit |
a4aae4 |
represent responses from a local HTTP/1.1 cache. The stream and
|
|
Packit |
a4aae4 |
headers pointer are passed to the parent (HTTPResponse); there's no
|
|
Packit |
a4aae4 |
temporary file for the parent to manage since the body is read from a
|
|
Packit |
a4aae4 |
file managed by the cache subsystem. This class releases the lock on
|
|
Packit |
a4aae4 |
the cache entry when the destructor is called. */
|
|
Packit |
a4aae4 |
HTTPCacheResponse(FILE *s, int status_code, vector<string> *headers, HTTPCache *c)
|
|
Packit |
a4aae4 |
: HTTPResponse(s, status_code, headers, ""), d_cache(c)
|
|
Packit |
a4aae4 |
{}
|
|
Packit |
a4aae4 |
|
|
Packit |
a4aae4 |
/** Build a Response object. Instances of this class are used to
|
|
Packit |
a4aae4 |
represent responses from a local HTTP/1.1 cache. The stream and
|
|
Packit |
a4aae4 |
headers pointer are passed to the parent (HTTPResponse); there's no
|
|
Packit |
a4aae4 |
temporary file for the parent to manage since the body is read from a
|
|
Packit |
a4aae4 |
file managed by the cache subsystem. This class releases the lock on
|
|
Packit |
a4aae4 |
the cache entry when the destructor is called. */
|
|
Packit |
a4aae4 |
HTTPCacheResponse(FILE *s, int status_code, vector<string> *headers,
|
|
Packit |
a4aae4 |
const string &file_name, HTTPCache *c)
|
|
Packit |
a4aae4 |
: HTTPResponse(s, status_code, headers, file_name), d_cache(c)
|
|
Packit |
a4aae4 |
{}
|
|
Packit |
a4aae4 |
|
|
Packit |
a4aae4 |
/** Free the cache entry lock. Call the parent's destructor. */
|
|
Packit |
a4aae4 |
virtual ~HTTPCacheResponse()
|
|
Packit |
a4aae4 |
{
|
|
Packit |
a4aae4 |
DBG(cerr << "Freeing HTTPCache resources... ");
|
|
Packit |
a4aae4 |
set_file(""); // This keeps ~HTTPResponse() from removing the cache entry.
|
|
Packit |
a4aae4 |
d_cache->release_cached_response(get_stream());
|
|
Packit |
a4aae4 |
DBGN(cerr << endl);
|
|
Packit |
a4aae4 |
}
|
|
Packit |
a4aae4 |
};
|
|
Packit |
a4aae4 |
|
|
Packit |
a4aae4 |
} // namespace libdap
|
|
Packit |
a4aae4 |
|
|
Packit |
a4aae4 |
#endif // cache_http_response_h
|