Multi-line svn commit, see body.
[shibboleth/cpp-opensaml.git] / saml / binding / HTTPResponse.h
index e77e17d..6c87fdb 100644 (file)
@@ -1,5 +1,5 @@
 /*
- *  Copyright 2001-2006 Internet2
+ *  Copyright 2001-2007 Internet2
  * 
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -43,13 +43,17 @@ namespace opensaml {
     public:
         virtual ~HTTPResponse() {}
         
+        void setContentType(const char* type) {
+            setResponseHeader("Content-Type", type);
+        }
+        
         /**
          * Sets or clears a response header.
          * 
          * @param name  header name
          * @param value value to set, or NULL to clear
          */
-        virtual void setHeader(const char* name, const char* value)=0;
+        virtual void setResponseHeader(const char* name, const char* value)=0;
 
         /**
          * Sets a client cookie.
@@ -57,7 +61,11 @@ namespace opensaml {
          * @param name  cookie name
          * @param value value to set, or NULL to clear
          */
-        virtual void setCookie(const char* name, const char* value)=0;
+        virtual void setCookie(const char* name, const char* value) {
+            std::string cookie(name);
+            cookie = cookie + '=' + value;
+            setResponseHeader("Set-Cookie", cookie.c_str());
+        }
         
         /**
          * Redirect the client to the specified URL and complete the response.
@@ -71,8 +79,21 @@ namespace opensaml {
         /** Some common HTTP status codes. */
         enum status_t {
             SAML_HTTP_STATUS_OK = 200,
-            SAML_HTTP_STATUS_MOVED = 302
+            SAML_HTTP_STATUS_MOVED = 302,
+            SAML_HTTP_STATUS_FORBIDDEN = 403,
+            SAML_HTTP_STATUS_NOTFOUND = 404,
+            SAML_HTTP_STATUS_ERROR = 500
         };
+        
+        using GenericResponse::sendResponse;
+
+        long sendError(std::istream& inputStream) {
+            return sendResponse(inputStream, SAML_HTTP_STATUS_ERROR);
+        }
+
+        long sendResponse(std::istream& inputStream) {
+            return sendResponse(inputStream, SAML_HTTP_STATUS_OK);
+        }
     };
 };