Reducing header overuse, non-inlining selected methods (CPPOST-35).
[shibboleth/cpp-xmltooling.git] / xmltooling / io / HTTPResponse.h
1 /*
2  *  Copyright 2001-2009 Internet2
3  * 
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 /**
18  * @file xmltooling/io/HTTPResponse.h
19  * 
20  * Interface to HTTP responses.
21  */
22
23 #ifndef __xmltooling_httpres_h__
24 #define __xmltooling_httpres_h__
25
26 #include <xmltooling/io/GenericResponse.h>
27
28 namespace xmltooling {
29     
30     /**
31      * Interface to HTTP response.
32      * 
33      * <p>To supply information to the surrounding web server environment,
34      * a shim must be supplied in the form of this interface to adapt the
35      * library to different proprietary server APIs.
36      * 
37      * <p>This interface need not be threadsafe.
38      */
39     class XMLTOOL_API HTTPResponse : public GenericResponse {
40     protected:
41         HTTPResponse();
42     public:
43         virtual ~HTTPResponse();
44         
45         void setContentType(const char* type);
46         
47         /**
48          * Sets or clears a response header.
49          * 
50          * @param name  header name
51          * @param value value to set, or NULL to clear
52          */
53         virtual void setResponseHeader(const char* name, const char* value)=0;
54
55         /**
56          * Sets a client cookie.
57          * 
58          * @param name  cookie name
59          * @param value value to set, or NULL to clear
60          */
61         virtual void setCookie(const char* name, const char* value);
62         
63         /**
64          * Redirect the client to the specified URL and complete the response.
65          * Any headers previously set will be sent ahead of the redirect.
66          * 
67          * @param url   location to redirect client
68          * @return a result code to return from the calling MessageEncoder
69          */
70         virtual long sendRedirect(const char* url)=0;
71         
72         /** Some common HTTP status codes. */
73         enum status_t {
74             XMLTOOLING_HTTP_STATUS_OK = 200,
75             XMLTOOLING_HTTP_STATUS_MOVED = 302,
76             XMLTOOLING_HTTP_STATUS_UNAUTHORIZED = 401,
77             XMLTOOLING_HTTP_STATUS_FORBIDDEN = 403,
78             XMLTOOLING_HTTP_STATUS_NOTFOUND = 404,
79             XMLTOOLING_HTTP_STATUS_ERROR = 500
80         };
81         
82         long sendError(std::istream& inputStream);
83
84         using GenericResponse::sendResponse;
85         long sendResponse(std::istream& inputStream);
86     };
87 };
88
89 #endif /* __xmltooling_httpres_h__ */