2 * Copyright 2001-2009 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 responses.
23 #ifndef __xmltooling_httpres_h__
24 #define __xmltooling_httpres_h__
26 #include <xmltooling/io/GenericResponse.h>
31 namespace xmltooling {
33 #if defined (_MSC_VER)
34 #pragma warning( push )
35 #pragma warning( disable : 4251 )
39 * Interface to HTTP response.
41 * <p>To supply information to the surrounding web server environment,
42 * a shim must be supplied in the form of this interface to adapt the
43 * library to different proprietary server APIs.
45 * <p>This interface need not be threadsafe.
47 class XMLTOOL_API HTTPResponse : public GenericResponse {
51 virtual ~HTTPResponse();
53 void setContentType(const char* type);
56 * Sets or clears a response header.
58 * @param name header name
59 * @param value value to set, or NULL to clear
61 virtual void setResponseHeader(const char* name, const char* value);
64 * Sets a client cookie.
66 * @param name cookie name
67 * @param value value to set, or NULL to clear
69 virtual void setCookie(const char* name, const char* value);
72 * Redirect the client to the specified URL and complete the response.
74 * <p>Any headers previously set will be sent ahead of the redirect.
76 * <p>The URL will be validated with the sanitizeURL method below.
78 * @param url location to redirect client
79 * @return a result code to return from the calling MessageEncoder
81 virtual long sendRedirect(const char* url);
83 /** Some common HTTP status codes. */
85 XMLTOOLING_HTTP_STATUS_OK = 200,
86 XMLTOOLING_HTTP_STATUS_MOVED = 302,
87 XMLTOOLING_HTTP_STATUS_NOTMODIFIED = 304,
88 XMLTOOLING_HTTP_STATUS_UNAUTHORIZED = 401,
89 XMLTOOLING_HTTP_STATUS_FORBIDDEN = 403,
90 XMLTOOLING_HTTP_STATUS_NOTFOUND = 404,
91 XMLTOOLING_HTTP_STATUS_ERROR = 500
94 long sendError(std::istream& inputStream);
96 using GenericResponse::sendResponse;
97 long sendResponse(std::istream& inputStream);
100 * Returns a modifiable array of schemes to permit in sanitized URLs.
102 * <p>Updates to this array must be externally synchronized with any use
103 * of this class or its subclasses.
105 * @return a mutable array of strings containing the schemes to permit
107 static std::vector<std::string>& getAllowedSchemes();
110 * Manually check for unsafe URLs vulnerable to injection attacks.
112 * @param url location to check
114 static void sanitizeURL(const char* url);
117 static std::vector<std::string> m_allowedSchemes;
120 #if defined (_MSC_VER)
121 #pragma warning( pop )
125 #endif /* __xmltooling_httpres_h__ */