Selaa lähdekoodia

refactored should_keep_alive() for better readability

Sergey Lyubka 13 vuotta sitten
vanhempi
commit
594a37d51d
1 muutettua tiedostoa jossa 8 lisäystä ja 5 poistoa
  1. 8 5
      mongoose.c

+ 8 - 5
mongoose.c

@@ -827,11 +827,14 @@ static int match_prefix(const char *pattern, int pattern_len, const char *str) {
 static int should_keep_alive(const struct mg_connection *conn) {
   const char *http_version = conn->request_info.http_version;
   const char *header = mg_get_header(conn, "Connection");
-  return !(conn->must_close == 1 ||
-           conn->request_info.status_code == 401 ||
-           mg_strcasecmp(conn->ctx->config[ENABLE_KEEP_ALIVE], "yes") != 0 ||
-           (header != NULL && mg_strcasecmp(header, "keep-alive") != 0) ||
-           (header == NULL && http_version && strcmp(http_version, "1.1")));
+  if (conn->must_close == 1 ||
+      conn->request_info.status_code == 401 ||
+      mg_strcasecmp(conn->ctx->config[ENABLE_KEEP_ALIVE], "yes") != 0 ||
+      (header != NULL && mg_strcasecmp(header, "keep-alive") != 0) ||
+      (header == NULL && http_version && strcmp(http_version, "1.1"))) {
+    return 0;
+  }
+  return 1;
 }
 
 static const char *suggest_connection_header(const struct mg_connection *conn) {