]> granicus.if.org Git - apache/commitdiff
Allow headers (if not already passed by other means) to be sent via
authorWilliam A. Rowe Jr <wrowe@apache.org>
Wed, 29 Jan 2003 16:02:17 +0000 (16:02 +0000)
committerWilliam A. Rowe Jr <wrowe@apache.org>
Wed, 29 Jan 2003 16:02:17 +0000 (16:02 +0000)
  WriteFile() since the foxisapi and other thunks seem to indicate that
  headers within the WriteFile() operation are expected to succeed.

  Also assure that all ->completion callbacks get the original size of
  the document.

git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@98533 13f79535-47bb-0310-9956-ffa450edef68

modules/arch/win32/mod_isapi.c

index 9349663db5495e2f9ccc34b57ac0c1f14a66b43e..f8bfdb68d31306f13ec12f4ba00afd76681ecdfc 100644 (file)
@@ -626,38 +626,6 @@ int APR_THREAD_FUNC GetServerVariable (isapi_cid    *cid,
     return 0;
 }
 
-int APR_THREAD_FUNC WriteClient(isapi_cid    *cid, 
-                                void         *buf_data, 
-                                apr_uint32_t *buf_size, 
-                                apr_uint32_t  flags)
-{
-    request_rec *r = cid->r;
-    conn_rec *c = r->connection;
-    apr_bucket_brigade *bb;
-    apr_bucket *b;
-    apr_status_t rv;
-
-    bb = apr_brigade_create(r->pool, c->bucket_alloc);
-    b = apr_bucket_transient_create(buf_data, *buf_size, c->bucket_alloc);
-    APR_BRIGADE_INSERT_TAIL(bb, b);
-    b = apr_bucket_flush_create(c->bucket_alloc);
-    APR_BRIGADE_INSERT_TAIL(bb, b);
-    rv = ap_pass_brigade(r->output_filters, bb);
-    cid->response_sent = 1;
-
-    if ((flags & HSE_IO_ASYNC) && cid->completion) {
-        if (rv == OK) {
-            cid->completion(cid->ecb, cid->completion_arg, 
-                            *buf_size, ERROR_SUCCESS);
-        }
-        else {
-            cid->completion(cid->ecb, cid->completion_arg, 
-                            *buf_size, ERROR_WRITE_FAULT);
-        }
-    }
-    return (rv == OK);
-}
-
 int APR_THREAD_FUNC ReadClient(isapi_cid    *cid, 
                                void         *buf_data, 
                                apr_uint32_t *buf_size)
@@ -813,6 +781,58 @@ static apr_ssize_t send_response_header(isapi_cid *cid,
     return ate;
 }
 
+int APR_THREAD_FUNC WriteClient(isapi_cid    *cid, 
+                                void         *buf_data, 
+                                apr_uint32_t *size_arg, 
+                                apr_uint32_t  flags)
+{
+    request_rec *r = cid->r;
+    conn_rec *c = r->connection;
+    apr_uint32_t buf_size = *size_arg;
+    apr_bucket_brigade *bb;
+    apr_bucket *b;
+    apr_status_t rv;
+
+    if (!cid->headers_set) {
+        /* It appears that the foxisapi module and other clients
+         * presume that WriteClient("headers\n\nbody") will work.
+         * Parse them out, or die trying.
+         */
+        apr_ssize_t ate;
+        ate = send_response_header(cid, (char*)buf_data,
+                                   NULL, buf_size, 0);
+        if (ate < 0) {
+            SetLastError(ERROR_INVALID_PARAMETER);
+            return 0;
+        }
+
+        (char*)buf_data += ate;
+        buf_size -= ate;
+    }
+
+    if (buf_size) {
+        bb = apr_brigade_create(r->pool, c->bucket_alloc);
+        b = apr_bucket_transient_create(buf_data, buf_size, c->bucket_alloc);
+        APR_BRIGADE_INSERT_TAIL(bb, b);
+        b = apr_bucket_flush_create(c->bucket_alloc);
+        APR_BRIGADE_INSERT_TAIL(bb, b);
+        rv = ap_pass_brigade(r->output_filters, bb);
+        cid->response_sent = 1;
+    }
+
+    if ((flags & HSE_IO_ASYNC) && cid->completion) {
+        if (rv == OK) {
+            cid->completion(cid->ecb, cid->completion_arg, 
+                            *size_arg, ERROR_SUCCESS);
+        }
+        else {
+            cid->completion(cid->ecb, cid->completion_arg, 
+                            *size_arg, ERROR_WRITE_FAULT);
+        }
+    }
+    return (rv == OK);
+}
+
 int APR_THREAD_FUNC ServerSupportFunction(isapi_cid    *cid, 
                                           apr_uint32_t  HSE_code,
                                           void         *buf_data, 
@@ -1042,10 +1062,11 @@ int APR_THREAD_FUNC ServerSupportFunction(isapi_cid    *cid,
         }
 
         if (tf->pHead && (apr_size_t)ate < tf->HeadLength) {
-            sent = tf->HeadLength - ate;
             b = apr_bucket_transient_create((char*)tf->pHead + ate, 
-                                            sent, c->bucket_alloc);
+                                            tf->HeadLength - ate,
+                                            c->bucket_alloc);
             APR_BRIGADE_INSERT_TAIL(bb, b);
+            sent = tf->HeadLength;
         }
 
         sent += (apr_uint32_t)fsize;
@@ -1576,6 +1597,8 @@ apr_status_t isapi_handler (request_rec *r)
         bb = apr_brigade_create(r->pool, c->bucket_alloc);
         b = apr_bucket_eos_create(c->bucket_alloc);
         APR_BRIGADE_INSERT_TAIL(bb, b);
+        b = apr_bucket_flush_create(c->bucket_alloc);
+        APR_BRIGADE_INSERT_TAIL(bb, b);
         rv = ap_pass_brigade(r->output_filters, bb);
         cid->response_sent = 1;