Fix HTTP Close
[yazpp-moved-to-github.git] / src / yaz-proxy.cpp
index 97ec2de..33a2e25 100644 (file)
@@ -2,7 +2,7 @@
  * Copyright (c) 1998-2004, Index Data.
  * See the file LICENSE for details.
  * 
- * $Id: yaz-proxy.cpp,v 1.91 2004-01-15 23:44:58 adam Exp $
+ * $Id: yaz-proxy.cpp,v 1.93 2004-01-30 00:38:28 adam Exp $
  */
 
 #include <assert.h>
@@ -706,7 +706,11 @@ int Yaz_Proxy::send_http_response(int code)
     Z_HTTP_Response *hres = gdu->u.HTTP_Response;
     if (m_http_version)
        hres->version = odr_strdup(o, m_http_version);
-    m_http_keepalive = 0;
+    if (m_http_keepalive)
+        z_HTTP_header_add(o, &hres->headers, "Connection", "Keep-Alive");
+    else
+       timeout(0);
+    
     if (m_log_mask & PROXY_LOG_REQ_CLIENT)
     {
        yaz_log (LOG_LOG, "%sSending %s to client", m_session_str,
@@ -729,6 +733,8 @@ int Yaz_Proxy::send_srw_response(Z_SRW_PDU *srw_pdu)
     z_HTTP_header_add(o, &hres->headers, "Content-Type", ctype);
     if (m_http_keepalive)
         z_HTTP_header_add(o, &hres->headers, "Connection", "Keep-Alive");
+    else
+       timeout(0);
 
     static Z_SOAP_Handler soap_handlers[2] = {
 #if HAVE_XSLT
@@ -769,8 +775,7 @@ int Yaz_Proxy::send_to_srw_client_error(int srw_error, const char *add)
     srw_res->num_diagnostics = 1;
     srw_res->diagnostics = (Z_SRW_diagnostic *)
        odr_malloc(o, sizeof(*srw_res->diagnostics));
-    srw_res->diagnostics[0].code =  odr_intdup(o, srw_error);
-    srw_res->diagnostics[0].details = add ? odr_strdup(o, add) : 0;
+    yaz_mk_std_diagnostic(o, srw_res->diagnostics, srw_error, add);
     return send_srw_response(srw_pdu);
 }
 
@@ -783,9 +788,9 @@ int Yaz_Proxy::z_to_srw_diag(ODR o, Z_SRW_searchRetrieveResponse *srw_res,
     srw_res->num_diagnostics = 1;
     srw_res->diagnostics = (Z_SRW_diagnostic *)
        odr_malloc(o, sizeof(*srw_res->diagnostics));
-    srw_res->diagnostics[0].code = 
-       odr_intdup(o, yaz_diag_bib1_to_srw(*ddf->condition));
-    srw_res->diagnostics[0].details = ddf->u.v2Addinfo;
+    yaz_mk_std_diagnostic(o, srw_res->diagnostics,
+                         yaz_diag_bib1_to_srw(*ddf->condition), 
+                         ddf->u.v2Addinfo);
     return 0;
 }
 
@@ -1049,18 +1054,6 @@ int Yaz_Proxy::send_to_client(Z_APDU *apdu)
        m_client = 0;
        m_parent->pre_init();
     }
-    if (m_http_version)
-    {
-       if (!m_http_keepalive)
-       {
-#if 1
-           timeout(1);
-#else
-           shutdown();
-           return -1;
-#endif
-       }
-    }
     return r;
 }
 
@@ -1867,8 +1860,8 @@ void Yaz_Proxy::handle_incoming_HTTP(Z_HTTP_Request *hreq)
     }
     int len = 0;
     Z_GDU *p = z_get_HTTP_Response(odr_encode(), 400);
+    timeout(0);
     send_GDU(p, &len);
-    timeout(1);
 }
 
 void Yaz_Proxy::handle_incoming_Z_PDU(Z_APDU *apdu)