Browse code

core: tcp - handle http read on \n\n EOH and deal with HTTP Via header

- handling \n\n for http makes same code as for sip, being easier to
test injecting a request from file
- HTTP Via is not compatible with SIP Via, resulting in errors - replace
its name with Hia to be ignored. FS#237

Daniel-Constantin Mierla authored on 06/01/2015 22:23:43
Showing 1 changed files
... ...
@@ -172,6 +172,16 @@ int tcp_http11_continue(struct tcp_connection *c)
172 172
 		c->req.flags |= F_TCP_REQ_BCHUNKED;
173 173
 		ret = 1;
174 174
 	}
175
+	/* check for HTTP Via header
176
+	 * - HTTP Via format is different that SIP Via
177
+	 * - workaround: replace with Hia to be ignored by SIP parser
178
+	 */
179
+	if((p=strfindcasestrz(&msg, "\nVia:"))!=NULL)
180
+	{
181
+		p++;
182
+		*p = 'H';
183
+		LM_DBG("replaced HTTP Via with Hia [[\n%.*s]]\n", msg.len, msg.s);
184
+	}
175 185
 	return ret;
176 186
 }
177 187
 #endif /* HTTP11 */
... ...
@@ -452,6 +462,10 @@ int tcp_read_headers(struct tcp_connection *c, int* read_flags)
452 452
 					case '\n':
453 453
 						/* found LF LF */
454 454
 						r->state=H_BODY;
455
+#ifdef READ_HTTP11
456
+						if (cfg_get(tcp, tcp_cfg, accept_no_cl)!=0)
457
+							tcp_http11_continue(c);
458
+#endif
455 459
 						if (TCP_REQ_HAS_CLEN(r)){
456 460
 							r->body=p+1;
457 461
 							r->bytes_to_go=r->content_len;
... ...
@@ -461,9 +475,42 @@ int tcp_read_headers(struct tcp_connection *c, int* read_flags)
461 461
 								goto skip;
462 462
 							}
463 463
 						}else{
464
-							DBG("tcp_read_headers: ERROR: no clen, p=%X\n",
465
-									*p);
466
-							r->error=TCP_REQ_BAD_LEN;
464
+							if(cfg_get(tcp, tcp_cfg, accept_no_cl)!=0) {
465
+#ifdef READ_MSRP
466
+								/* if MSRP message */
467
+								if(c->req.flags&F_TCP_REQ_MSRP_FRAME)
468
+								{
469
+									r->body=p+1;
470
+									/* at least 3 bytes: 0\r\n */
471
+									r->bytes_to_go=3;
472
+									p++;
473
+									r->content_len = 0;
474
+									r->state=H_MSRP_BODY;
475
+									break;
476
+								}
477
+#endif
478
+
479
+#ifdef READ_HTTP11
480
+								if(TCP_REQ_BCHUNKED(r)) {
481
+									r->body=p+1;
482
+									/* at least 3 bytes: 0\r\n */
483
+									r->bytes_to_go=3;
484
+									p++;
485
+									r->content_len = 0;
486
+									r->state=H_HTTP11_CHUNK_START;
487
+									break;
488
+								}
489
+#endif
490
+								r->body=p+1;
491
+								r->bytes_to_go=0;
492
+								r->flags|=F_TCP_REQ_COMPLETE;
493
+								p++;
494
+								goto skip;
495
+							} else {
496
+								DBG("tcp_read_headers: ERROR: no clen, p=%X\n",
497
+										*p);
498
+								r->error=TCP_REQ_BAD_LEN;
499
+							}
467 500
 						}
468 501
 						break;
469 502
 					case '-':