2 * Copyright 2001-2007 Internet2
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 * @file xmltooling/io/HTTPResponse.h
20 * Interface to HTTP response.
23 #ifndef __xmltooling_httpres_h__
24 #define __xmltooling_httpres_h__
26 #include <xmltooling/io/GenericResponse.h>
28 namespace xmltooling {
31 * Interface to HTTP response.
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.
37 * <p>This interface need not be threadsafe.
39 class XMLTOOL_API HTTPResponse : public GenericResponse {
43 virtual ~HTTPResponse() {}
45 void setContentType(const char* type) {
46 setResponseHeader("Content-Type", type);
50 * Sets or clears a response header.
52 * @param name header name
53 * @param value value to set, or NULL to clear
55 virtual void setResponseHeader(const char* name, const char* value)=0;
58 * Sets a client cookie.
60 * @param name cookie name
61 * @param value value to set, or NULL to clear
63 virtual void setCookie(const char* name, const char* value) {
64 std::string cookie(name);
65 cookie = cookie + '=' + value;
66 setResponseHeader("Set-Cookie", cookie.c_str());
70 * Redirect the client to the specified URL and complete the response.
71 * Any headers previously set will be sent ahead of the redirect.
73 * @param url location to redirect client
74 * @return a result code to return from the calling MessageEncoder
76 virtual long sendRedirect(const char* url)=0;
78 /** Some common HTTP status codes. */
80 XMLTOOLING_HTTP_STATUS_OK = 200,
81 XMLTOOLING_HTTP_STATUS_MOVED = 302,
82 XMLTOOLING_HTTP_STATUS_UNAUTHORIZED = 401,
83 XMLTOOLING_HTTP_STATUS_FORBIDDEN = 403,
84 XMLTOOLING_HTTP_STATUS_NOTFOUND = 404,
85 XMLTOOLING_HTTP_STATUS_ERROR = 500
88 using GenericResponse::sendResponse;
90 long sendError(std::istream& inputStream) {
91 return sendResponse(inputStream, XMLTOOLING_HTTP_STATUS_ERROR);
94 long sendResponse(std::istream& inputStream) {
95 return sendResponse(inputStream, XMLTOOLING_HTTP_STATUS_OK);
100 #endif /* __xmltooling_httpres_h__ */