Remove api directory from dist.
[shibboleth/cpp-sp.git] / apache / mod_shib.cpp
index fe7d038..5652713 100644 (file)
@@ -345,7 +345,7 @@ public:
   shib_server_config* m_sc;
   shib_request_config* m_rc;
 
-  ShibTargetApache(request_rec* req) : AbstractSPRequest(SHIBSP_LOGCAT".Apache"),
+  ShibTargetApache(request_rec* req) : AbstractSPRequest(SHIBSP_LOGCAT ".Apache"),
         m_gotBody(false),m_firsttime(true),
 #if defined(SHIBSP_HAVE_GSSAPI) && !defined(SHIB_APACHE_13)
         m_gssname(GSS_C_NO_NAME),
@@ -415,7 +415,11 @@ public:
     return type ? type : "";
   }
   long getContentLength() const {
-      return m_gotBody ? m_body.length() : m_req->remaining;
+      // Apache won't expose content length until the body's read.
+      if (!m_gotBody) {
+          getRequestBody();
+      }
+      return m_body.length();
   }
   string getRemoteAddr() const {
     string ret = AbstractSPRequest::getRemoteAddr();
@@ -598,19 +602,23 @@ public:
       m_req->content_type = ap_psprintf(m_req->pool, "%s", type);
   }
   void setResponseHeader(const char* name, const char* value) {
-   HTTPResponse::setResponseHeader(name, value);
+    HTTPResponse::setResponseHeader(name, value);
+    if (name) {
 #ifdef SHIB_DEFERRED_HEADERS
-   if (!m_rc)
-      // this happens on subrequests
-      m_rc = get_request_config(m_req);
-    if (m_handler) {
-        if (!m_rc->hdr_out)
-            m_rc->hdr_out = ap_make_table(m_req->pool, 5);
-        ap_table_add(m_rc->hdr_out, name, value);
-    }
-    else
+        if (!m_rc) {
+            // this happens on subrequests
+            m_rc = get_request_config(m_req);
+        }
+        if (m_handler) {
+            if (!m_rc->hdr_out) {
+                m_rc->hdr_out = ap_make_table(m_req->pool, 5);
+            }
+            ap_table_add(m_rc->hdr_out, name, value);
+        }
+        else
 #endif
-    ap_table_add(m_req->err_headers_out, name, value);
+            ap_table_add(m_req->err_headers_out, name, value);
+    }
   }
   long sendResponse(istream& in, long status) {
     if (status != XMLTOOLING_HTTP_STATUS_OK)
@@ -873,8 +881,9 @@ extern "C" int shib_auth_checker(request_rec* r)
 #else
         shib_request_config* rc = (shib_request_config*)ap_get_module_config(r->request_config, &mod_shib);
         if (!rc || !rc->sta) {
-            ap_log_rerror(APLOG_MARK, APLOG_ERR|APLOG_NOERRNO, SH_AP_R(r), "shib_auth_checker found no per-request structure");
-            return SERVER_ERROR;
+            ap_log_rerror(APLOG_MARK, APLOG_INFO|APLOG_NOERRNO, SH_AP_R(r), "shib_auth_checker found no per-request structure");
+            shib_post_read(r);  // ensures objects are created if post_read hook didn't run
+            rc = (shib_request_config*)ap_get_module_config(r->request_config, &mod_shib);
         }
         ShibTargetApache* psta = rc->sta;
 #endif