Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Works out how requests are finalized and connections closed.

  • Loading branch information...
commit ba9f1159aeb01438f0c4c1d1610e98c0d2e579cf 1 parent 0c4d1e5
@alobbs alobbs authored
View
2  cherokee/connection-protected.h
@@ -252,7 +252,7 @@ struct cherokee_connection {
*/
ret_t cherokee_connection_new (cherokee_connection_t **conn);
ret_t cherokee_connection_free (cherokee_connection_t *conn);
-ret_t cherokee_connection_clean (cherokee_connection_t *conn);
+ret_t cherokee_connection_clean (cherokee_connection_t *conn, cherokee_boolean_t reuse);
ret_t cherokee_connection_clean_close (cherokee_connection_t *conn);
/* Close
View
31 cherokee/connection.c
@@ -242,7 +242,8 @@ cherokee_connection_free (cherokee_connection_t *conn)
ret_t
-cherokee_connection_clean (cherokee_connection_t *conn)
+cherokee_connection_clean (cherokee_connection_t *conn,
+ cherokee_boolean_t reuse)
{
size_t crlf_len;
uint32_t header_len;
@@ -371,19 +372,23 @@ cherokee_connection_clean (cherokee_connection_t *conn)
cherokee_buffer_clean (&conn->buffer);
cherokee_buffer_clean (&conn->header_buffer);
- /* Skip trailing CRLF (which may be sent by some HTTP clients)
- * only if the number of CRLFs is within the predefine count
- * limit otherwise ignore trailing CRLFs so that they will be
- * handled in next request. This may avoid a subsequent real
- * move_to_begin of the contents left in the buffer.
- */
- crlf_len = cherokee_buffer_cnt_spn (&conn->incoming_header, header_len, CRLF);
- header_len += (crlf_len <= MAX_HEADER_CRLF) ? crlf_len : 0;
+ if (reuse) {
+ /* Skip trailing CRLF (which may be sent by some HTTP clients)
+ * only if the number of CRLFs is within the predefine count
+ * limit otherwise ignore trailing CRLFs so that they will be
+ * handled in next request. This may avoid a subsequent real
+ * move_to_begin of the contents left in the buffer.
+ */
+ crlf_len = cherokee_buffer_cnt_spn (&conn->incoming_header, header_len, CRLF);
+ header_len += (crlf_len <= MAX_HEADER_CRLF) ? crlf_len : 0;
- cherokee_buffer_move_to_begin (&conn->incoming_header, header_len);
+ cherokee_buffer_move_to_begin (&conn->incoming_header, header_len);
- TRACE (ENTRIES, "conn %p, %s headers\n", conn,
- !cherokee_buffer_is_empty (&conn->incoming_header) ? "has" : "doesn't have");
+ TRACE (ENTRIES, "conn %p, %s headers\n", conn,
+ !cherokee_buffer_is_empty (&conn->incoming_header) ? "has" : "doesn't have");
+ } else {
+ cherokee_buffer_clean (&conn->incoming_header);
+ }
return ret_ok;
}
@@ -404,7 +409,7 @@ cherokee_connection_clean_close (cherokee_connection_t *conn)
/* Clean the connection object
*/
- cherokee_connection_clean (conn);
+ cherokee_connection_clean (conn, false);
return ret_ok;
}
View
17 cherokee/thread.c
@@ -377,7 +377,8 @@ close_active_connection (cherokee_thread_t *thread,
static void
-maybe_purge_closed_connection (cherokee_thread_t *thread, cherokee_connection_t *conn)
+finalize_request (cherokee_thread_t *thread,
+ cherokee_connection_t *conn)
{
/* CONNECTION CLOSE: If it isn't a keep-alive connection, it
* should try to perform a lingering close (there is no need
@@ -405,7 +406,7 @@ maybe_purge_closed_connection (cherokee_thread_t *thread, cherokee_connection_t
/* Clean the connection
*/
- cherokee_connection_clean (conn);
+ cherokee_connection_clean (conn, true);
/* Update the timeout value
*/
@@ -1174,11 +1175,11 @@ process_active_connections (cherokee_thread_t *thd)
case ret_ok:
if (!http_method_with_body (conn->header.method)) {
- maybe_purge_closed_connection (thd, conn);
+ finalize_request (thd, conn);
continue;
}
if (!http_code_with_body (conn->error_code)) {
- maybe_purge_closed_connection (thd, conn);
+ finalize_request (thd, conn);
continue;
}
break;
@@ -1208,7 +1209,7 @@ process_active_connections (cherokee_thread_t *thd)
continue;
case ret_eof:
- maybe_purge_closed_connection (thd, conn);
+ finalize_request (thd, conn);
continue;
case ret_error:
@@ -1216,7 +1217,7 @@ process_active_connections (cherokee_thread_t *thd)
continue;
default:
- maybe_purge_closed_connection (thd, conn);
+ finalize_request (thd, conn);
continue;
}
}
@@ -1237,7 +1238,7 @@ process_active_connections (cherokee_thread_t *thd)
switch (ret) {
case ret_ok:
- maybe_purge_closed_connection (thd, conn);
+ finalize_request (thd, conn);
continue;
case ret_eagain:
if (cherokee_connection_poll_is_set (&conn->polling_aim)) {
@@ -1275,7 +1276,7 @@ process_active_connections (cherokee_thread_t *thd)
break;
case ret_eof:
- maybe_purge_closed_connection (thd, conn);
+ finalize_request (thd, conn);
continue;
case ret_error:
Please sign in to comment.
Something went wrong with that request. Please try again.