Przeglądaj źródła

WebServer: Close the socket if Connection: keep-alive isn't requested

Ali Mohammad Pur 3 lat temu
rodzic
commit
0e173da86f
1 zmienionych plików z 8 dodań i 0 usunięć
  1. 8 0
      Userland/Services/WebServer/Client.cpp

+ 8 - 0
Userland/Services/WebServer/Client.cpp

@@ -203,6 +203,14 @@ ErrorOr<void> Client::send_response(InputStream& response, HTTP::HttpRequest con
         }
         }
     } while (true);
     } while (true);
 
 
+    auto keep_alive = false;
+    if (auto it = request.headers().find_if([](auto& header) { return header.name.equals_ignoring_case("Connection"); }); !it.is_end()) {
+        if (it->value.trim_whitespace().equals_ignoring_case("keep-alive"))
+            keep_alive = true;
+    }
+    if (!keep_alive)
+        m_socket->close();
+
     return {};
     return {};
 }
 }