nginx-0.0.1-2003-06-04-21:28:33 import
diff --git a/src/http/ngx_http_event.c b/src/http/ngx_http_event.c
index b4a9ae9..be6d391 100644
--- a/src/http/ngx_http_event.c
+++ b/src/http/ngx_http_event.c
@@ -1133,6 +1133,16 @@
 
     ctx->action = "keepalive";
 
+    if (c->tcp_nopush) {
+        if (ngx_tcp_push(c->fd) == NGX_ERROR) {
+            ngx_log_error(NGX_LOG_CRIT, c->log, ngx_socket_errno,
+                          ngx_tcp_push_n " failed");
+                ngx_http_close_connection(c);
+                return;
+        }
+        c->tcp_nopush = 0;
+    }
+
     if ((ngx_event_flags & NGX_HAVE_AIO_EVENT) || blocked) {
         ngx_http_keepalive_handler(rev);
     }
diff --git a/src/http/ngx_http_header_filter.c b/src/http/ngx_http_header_filter.c
index 8989f7c..0f7c953 100644
--- a/src/http/ngx_http_header_filter.c
+++ b/src/http/ngx_http_header_filter.c
@@ -4,6 +4,12 @@
 #include <ngx_http.h>
 #include <nginx.h>
 
+/* STUB probably, needed for ngx_freebsd_tcp_nopush_flush */
+#ifdef __FreeBSD__
+#include <ngx_freebsd_init.h>
+#endif
+
+
 
 static int ngx_http_header_filter_init(ngx_pool_t *pool);
 static int ngx_http_header_filter(ngx_http_request_t *r);
@@ -94,6 +100,23 @@
     ngx_chain_t       *ch;
     ngx_table_elt_t   *header;
 
+#ifdef __FreeBSD__
+
+    if (r->keepalive) {
+        if (ngx_freebsd_tcp_nopush_flush) {
+            r->connection->tcp_nopush_enabled = 1;
+        }
+
+    } else {
+        r->connection->tcp_nopush_enabled = 1;
+    }
+
+#else
+
+    r->connection->tcp_nopush_enabled = 1;
+
+#endif
+
     if (r->http_version < NGX_HTTP_VERSION_10) {
         return NGX_OK;
     }
@@ -219,12 +242,12 @@
         len += 28;
     }
 
-    if (r->keepalive == 0) {
-        /* "Connection: close\r\n" */
-        len += 19;
-    } else {
+    if (r->keepalive) {
         /* "Connection: keep-alive\r\n" */
         len += 24;
+    } else {
+        /* "Connection: close\r\n" */
+        len += 19;
     }
 
     header = (ngx_table_elt_t *) r->headers_out.headers->elts;
@@ -323,11 +346,11 @@
         h->last = ngx_cpymem(h->last, "Transfer-Encoding: chunked" CRLF, 28);
     }
 
-    if (r->keepalive == 0) {
-        h->last = ngx_cpymem(h->last, "Connection: close" CRLF, 19);
+    if (r->keepalive) {
+        h->last = ngx_cpymem(h->last, "Connection: keep-alive" CRLF, 24);
 
     } else {
-        h->last = ngx_cpymem(h->last, "Connection: keep-alive" CRLF, 24);
+        h->last = ngx_cpymem(h->last, "Connection: close" CRLF, 19);
     }
 
     for (i = 0; i < r->headers_out.headers->nelts; i++) {