[sr-dev] git:master:54c178a9: core: tcp - handle http read on \n\n EOH and deal with HTTP Via header

Daniel-Constantin Mierla miconda at gmail.com
Tue Jan 6 23:43:38 CET 2015


Module: kamailio
Branch: master
Commit: 54c178a9072339233085372e60e611ba889f46b3
URL: https://github.com/kamailio/kamailio/commit/54c178a9072339233085372e60e611ba889f46b3

Author: Daniel-Constantin Mierla <miconda at gmail.com>
Committer: Daniel-Constantin Mierla <miconda at gmail.com>
Date: 2015-01-06T23:23:43+01:00

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

---

Modified: tcp_read.c

---

Diff:  https://github.com/kamailio/kamailio/commit/54c178a9072339233085372e60e611ba889f46b3.diff
Patch: https://github.com/kamailio/kamailio/commit/54c178a9072339233085372e60e611ba889f46b3.patch

---

diff --git a/tcp_read.c b/tcp_read.c
index 4778662..08342cc 100644
--- a/tcp_read.c
+++ b/tcp_read.c
@@ -172,6 +172,16 @@ int tcp_http11_continue(struct tcp_connection *c)
 		c->req.flags |= F_TCP_REQ_BCHUNKED;
 		ret = 1;
 	}
+	/* check for HTTP Via header
+	 * - HTTP Via format is different that SIP Via
+	 * - workaround: replace with Hia to be ignored by SIP parser
+	 */
+	if((p=strfindcasestrz(&msg, "\nVia:"))!=NULL)
+	{
+		p++;
+		*p = 'H';
+		LM_DBG("replaced HTTP Via with Hia [[\n%.*s]]\n", msg.len, msg.s);
+	}
 	return ret;
 }
 #endif /* HTTP11 */
@@ -452,6 +462,10 @@ int tcp_read_headers(struct tcp_connection *c, int* read_flags)
 					case '\n':
 						/* found LF LF */
 						r->state=H_BODY;
+#ifdef READ_HTTP11
+						if (cfg_get(tcp, tcp_cfg, accept_no_cl)!=0)
+							tcp_http11_continue(c);
+#endif
 						if (TCP_REQ_HAS_CLEN(r)){
 							r->body=p+1;
 							r->bytes_to_go=r->content_len;
@@ -461,9 +475,42 @@ int tcp_read_headers(struct tcp_connection *c, int* read_flags)
 								goto skip;
 							}
 						}else{
-							DBG("tcp_read_headers: ERROR: no clen, p=%X\n",
-									*p);
-							r->error=TCP_REQ_BAD_LEN;
+							if(cfg_get(tcp, tcp_cfg, accept_no_cl)!=0) {
+#ifdef READ_MSRP
+								/* if MSRP message */
+								if(c->req.flags&F_TCP_REQ_MSRP_FRAME)
+								{
+									r->body=p+1;
+									/* at least 3 bytes: 0\r\n */
+									r->bytes_to_go=3;
+									p++;
+									r->content_len = 0;
+									r->state=H_MSRP_BODY;
+									break;
+								}
+#endif
+
+#ifdef READ_HTTP11
+								if(TCP_REQ_BCHUNKED(r)) {
+									r->body=p+1;
+									/* at least 3 bytes: 0\r\n */
+									r->bytes_to_go=3;
+									p++;
+									r->content_len = 0;
+									r->state=H_HTTP11_CHUNK_START;
+									break;
+								}
+#endif
+								r->body=p+1;
+								r->bytes_to_go=0;
+								r->flags|=F_TCP_REQ_COMPLETE;
+								p++;
+								goto skip;
+							} else {
+								DBG("tcp_read_headers: ERROR: no clen, p=%X\n",
+										*p);
+								r->error=TCP_REQ_BAD_LEN;
+							}
 						}
 						break;
 					case '-':




More information about the sr-dev mailing list