]> git.ipfire.org Git - thirdparty/cups.git/blobdiff - cups/http.c
Use httpAddrListen and new httpAddrClose in cupsd and other places that need it.
[thirdparty/cups.git] / cups / http.c
index f3e449b7af8de45de9f0a7219211b17494443d40..3db98fca2199eedf0beec728d55ea0223db9a8b5 100644 (file)
@@ -678,11 +678,7 @@ _httpDisconnect(http_t *http)              /* I - HTTP connection */
     http_shutdown_ssl(http);
 #endif /* HAVE_SSL */
 
-#ifdef WIN32
-  closesocket(http->fd);
-#else
-  close(http->fd);
-#endif /* WIN32 */
+  httpAddrClose(NULL, http->fd);
 
   http->fd = -1;
 }
@@ -817,11 +813,7 @@ httpFlush(http_t *http)                    /* I - HTTP connection */
       http_shutdown_ssl(http);
 #endif /* HAVE_SSL */
 
-#ifdef WIN32
-    closesocket(http->fd);
-#else
-    close(http->fd);
-#endif /* WIN32 */
+    httpAddrClose(NULL, http->fd);
 
     http->fd = -1;
   }
@@ -2727,11 +2719,7 @@ httpReconnect2(http_t *http,             /* I - HTTP connection */
   {
     DEBUG_printf(("2httpReconnect2: Closing socket %d...", http->fd));
 
-#ifdef WIN32
-    closesocket(http->fd);
-#else
-    close(http->fd);
-#endif /* WIN32 */
+    httpAddrClose(NULL, http->fd);
 
     http->fd = -1;
   }
@@ -2799,11 +2787,7 @@ httpReconnect2(http_t *http,             /* I - HTTP connection */
 
     if (http_setup_ssl(http) != 0)
     {
-#  ifdef WIN32
-      closesocket(http->fd);
-#  else
-      close(http->fd);
-#  endif /* WIN32 */
+      httpAddrClose(NULL, http->fd);
 
       return (-1);
     }
@@ -3270,11 +3254,7 @@ _httpUpdate(http_t        *http, /* I - HTTP connection */
     {
       if (http_setup_ssl(http) != 0)
       {
-#  ifdef WIN32
-       closesocket(http->fd);
-#  else
-       close(http->fd);
-#  endif /* WIN32 */
+        httpAddrClose(NULL, http->fd);
 
        *status = http->status = HTTP_STATUS_ERROR;
        return (0);
@@ -3949,13 +3929,17 @@ httpWriteResponse(http_t        *http,  /* I - HTTP connection */
   }
 
 #ifdef HAVE_SSL
-  if (status == HTTP_STATUS_UPGRADE_REQUIRED)
+  if (status == HTTP_STATUS_UPGRADE_REQUIRED ||
+      status == HTTP_STATUS_SWITCHING_PROTOCOLS)
   {
     if (!http->fields[HTTP_FIELD_CONNECTION][0])
       httpSetField(http, HTTP_FIELD_CONNECTION, "Upgrade");
 
     if (!http->fields[HTTP_FIELD_UPGRADE][0])
       httpSetField(http, HTTP_FIELD_UPGRADE, "TLS/1.2,TLS/1.1,TLS/1.0");
+
+    if (!http->fields[HTTP_FIELD_CONTENT_LENGTH][0])
+      httpSetField(http, HTTP_FIELD_CONTENT_LENGTH, "0");
   }
 #endif /* HAVE_SSL */
 
@@ -4014,8 +3998,8 @@ httpWriteResponse(http_t        *http,    /* I - HTTP connection */
 
     if (http->cookie)
     {
-      if (httpPrintf(http, "Set-Cookie: %s path=/%s\r\n", http->cookie,
-                     http->tls ? " secure" : "") < 1)
+      if (httpPrintf(http, "Set-Cookie: %s path=/ httponly%s\r\n",
+                    http->cookie, http->tls ? " secure" : "") < 1)
       {
        http->status = HTTP_STATUS_ERROR;
        return (-1);
@@ -4035,7 +4019,8 @@ httpWriteResponse(http_t        *http,    /* I - HTTP connection */
     return (-1);
   }
 
-  if (status == HTTP_STATUS_CONTINUE)
+  if (status == HTTP_STATUS_CONTINUE ||
+      status == HTTP_STATUS_SWITCHING_PROTOCOLS)
   {
    /*
     * Restore the old data_encoding and data_length values...
@@ -5737,11 +5722,7 @@ http_upgrade(http_t *http)               /* I - HTTP connection */
 
     DEBUG_puts("8http_upgrade: Server does not support HTTP upgrade!");
 
-#  ifdef WIN32
-    closesocket(http->fd);
-#  else
-    close(http->fd);
-#  endif
+    httpAddrClose(NULL, http->fd);
 
     http->fd = -1;