Skip to content
This repository
Browse code

Works out how requests are finalized and connections closed.

  • Loading branch information...
commit ba9f1159aeb01438f0c4c1d1610e98c0d2e579cf 1 parent 0c4d1e5
Alvaro Lopez Ortega authored
2  cherokee/connection-protected.h
@@ -252,7 +252,7 @@ struct cherokee_connection {
252 252
  */
253 253
 ret_t cherokee_connection_new                    (cherokee_connection_t **conn);
254 254
 ret_t cherokee_connection_free                   (cherokee_connection_t  *conn);
255  
-ret_t cherokee_connection_clean                  (cherokee_connection_t  *conn);
  255
+ret_t cherokee_connection_clean                  (cherokee_connection_t  *conn, cherokee_boolean_t reuse);
256 256
 ret_t cherokee_connection_clean_close            (cherokee_connection_t  *conn);
257 257
 
258 258
 /* Close
31  cherokee/connection.c
@@ -242,7 +242,8 @@ cherokee_connection_free (cherokee_connection_t  *conn)
242 242
 
243 243
 
244 244
 ret_t
245  
-cherokee_connection_clean (cherokee_connection_t *conn)
  245
+cherokee_connection_clean (cherokee_connection_t *conn,
  246
+			   cherokee_boolean_t     reuse)
246 247
 {
247 248
 	size_t             crlf_len;
248 249
 	uint32_t           header_len;
@@ -371,19 +372,23 @@ cherokee_connection_clean (cherokee_connection_t *conn)
371 372
 	cherokee_buffer_clean (&conn->buffer);
372 373
 	cherokee_buffer_clean (&conn->header_buffer);
373 374
 
374  
-	/* Skip trailing CRLF (which may be sent by some HTTP clients)
375  
-	 * only if the number of CRLFs is within the predefine count
376  
-	 * limit otherwise ignore trailing CRLFs so that they will be
377  
-	 * handled in next request.  This may avoid a subsequent real
378  
-	 * move_to_begin of the contents left in the buffer.
379  
-	 */
380  
-	crlf_len = cherokee_buffer_cnt_spn (&conn->incoming_header, header_len, CRLF);
381  
-	header_len += (crlf_len <= MAX_HEADER_CRLF) ? crlf_len : 0;
  375
+	if (reuse) {
  376
+		/* Skip trailing CRLF (which may be sent by some HTTP clients)
  377
+		 * only if the number of CRLFs is within the predefine count
  378
+		 * limit otherwise ignore trailing CRLFs so that they will be
  379
+		 * handled in next request.  This may avoid a subsequent real
  380
+		 * move_to_begin of the contents left in the buffer.
  381
+		 */
  382
+		crlf_len = cherokee_buffer_cnt_spn (&conn->incoming_header, header_len, CRLF);
  383
+		header_len += (crlf_len <= MAX_HEADER_CRLF) ? crlf_len : 0;
382 384
 
383  
-	cherokee_buffer_move_to_begin (&conn->incoming_header, header_len);
  385
+		cherokee_buffer_move_to_begin (&conn->incoming_header, header_len);
384 386
 
385  
-	TRACE (ENTRIES, "conn %p, %s headers\n", conn,
386  
-	       !cherokee_buffer_is_empty (&conn->incoming_header) ? "has" : "doesn't have");
  387
+		TRACE (ENTRIES, "conn %p, %s headers\n", conn,
  388
+		       !cherokee_buffer_is_empty (&conn->incoming_header) ? "has" : "doesn't have");
  389
+	} else {
  390
+		cherokee_buffer_clean (&conn->incoming_header);
  391
+	}
387 392
 
388 393
 	return ret_ok;
389 394
 }
@@ -404,7 +409,7 @@ cherokee_connection_clean_close (cherokee_connection_t *conn)
404 409
 
405 410
 	/* Clean the connection object
406 411
 	 */
407  
-	cherokee_connection_clean (conn);
  412
+	cherokee_connection_clean (conn, false);
408 413
 	return ret_ok;
409 414
 }
410 415
 
17  cherokee/thread.c
@@ -377,7 +377,8 @@ close_active_connection (cherokee_thread_t     *thread,
377 377
 
378 378
 
379 379
 static void
380  
-maybe_purge_closed_connection (cherokee_thread_t *thread, cherokee_connection_t *conn)
  380
+finalize_request (cherokee_thread_t     *thread,
  381
+		  cherokee_connection_t *conn)
381 382
 {
382 383
 	/* CONNECTION CLOSE: If it isn't a keep-alive connection, it
383 384
 	 * 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
405 406
 
406 407
 	/* Clean the connection
407 408
 	 */
408  
-	cherokee_connection_clean (conn);
  409
+	cherokee_connection_clean (conn, true);
409 410
 
410 411
 	/* Update the timeout value
411 412
 	 */
@@ -1174,11 +1175,11 @@ process_active_connections (cherokee_thread_t *thd)
1174 1175
 
1175 1176
 			case ret_ok:
1176 1177
 				if (!http_method_with_body (conn->header.method)) {
1177  
-					maybe_purge_closed_connection (thd, conn);
  1178
+					finalize_request (thd, conn);
1178 1179
 					continue;
1179 1180
 				}
1180 1181
 				if (!http_code_with_body (conn->error_code)) {
1181  
-					maybe_purge_closed_connection (thd, conn);
  1182
+					finalize_request (thd, conn);
1182 1183
 					continue;
1183 1184
 				}
1184 1185
 				break;
@@ -1208,7 +1209,7 @@ process_active_connections (cherokee_thread_t *thd)
1208 1209
 					continue;
1209 1210
 
1210 1211
 				case ret_eof:
1211  
-					maybe_purge_closed_connection (thd, conn);
  1212
+					finalize_request (thd, conn);
1212 1213
 					continue;
1213 1214
 
1214 1215
 				case ret_error:
@@ -1216,7 +1217,7 @@ process_active_connections (cherokee_thread_t *thd)
1216 1217
 					continue;
1217 1218
 
1218 1219
 				default:
1219  
-					maybe_purge_closed_connection (thd, conn);
  1220
+					finalize_request (thd, conn);
1220 1221
 					continue;
1221 1222
 				}
1222 1223
 			}
@@ -1237,7 +1238,7 @@ process_active_connections (cherokee_thread_t *thd)
1237 1238
 
1238 1239
 				switch (ret) {
1239 1240
 				case ret_ok:
1240  
-					maybe_purge_closed_connection (thd, conn);
  1241
+					finalize_request (thd, conn);
1241 1242
 					continue;
1242 1243
 				case ret_eagain:
1243 1244
 					if (cherokee_connection_poll_is_set (&conn->polling_aim)) {
@@ -1275,7 +1276,7 @@ process_active_connections (cherokee_thread_t *thd)
1275 1276
 				break;
1276 1277
 
1277 1278
 			case ret_eof:
1278  
-				maybe_purge_closed_connection (thd, conn);
  1279
+				finalize_request (thd, conn);
1279 1280
 				continue;
1280 1281
 
1281 1282
 			case ret_error:

0 notes on commit ba9f115

Please sign in to comment.
Something went wrong with that request. Please try again.