Browse code

core: tcp_read.c insensitive search for HTTP11 headers

root authored on 21/09/2010 12:11:33
Showing 1 changed files
... ...
@@ -122,16 +122,39 @@ static struct local_timer tcp_reader_ltimer;
122 122
 static ticks_t tcp_reader_prev_ticks;
123 123
 
124 124
 #ifdef READ_HTTP11
125
+static inline char *strfindcasestrz(str *haystack, char *needlez)
126
+{
127
+	int i,j;
128
+	str needle;
129
+
130
+	needle.s = needlez;
131
+	needle.len = strlen(needlez);
132
+	for(i=0;i<haystack->len-needle.len;i++) {
133
+		for(j=0;j<needle.len;j++) {
134
+			if ( !((haystack->s[i+j]==needle.s[j]) ||
135
+					( isalpha((int)haystack->s[i+j])
136
+						&& ((haystack->s[i+j])^(needle.s[j]))==0x20 )) )
137
+				break;
138
+		}
139
+		if (j==needle.len)
140
+			return haystack->s+i;
141
+	}
142
+	return 0;
143
+}
144
+
125 145
 int tcp_http11_continue(struct tcp_connection *c)
126 146
 {
127 147
 	struct dest_info dst;
128 148
 	char *p;
129 149
 	struct msg_start fline;
130 150
 	int ret;
151
+	str msg;
131 152
 
132 153
 	ret = 0;
133 154
 
134
-	p = parse_first_line(c->req.buf, c->req.pos - c->req.buf, &fline);
155
+	msg.s = c->req.start;
156
+	msg.len = c->req.pos - c->req.start;
157
+	p = parse_first_line(msg.s, msg.len, &fline);
135 158
 	if(p==NULL)
136 159
 		return 0;
137 160
 
... ...
@@ -145,7 +168,7 @@ int tcp_http11_continue(struct tcp_connection *c)
145 145
 		return 0;
146 146
 
147 147
 	/* check for Expect header */
148
-	if(strstr(c->req.start, "Expect: 100-continue")!=NULL)
148
+	if(strfindcasestrz(&msg, "Expect: 100-continue")!=NULL)
149 149
 	{
150 150
 		init_dst_from_rcv(&dst, &c->rcv);
151 151
 		if (tcp_send(&dst, 0, HTTP11CONTINUE, HTTP11CONTINUE_LEN) < 0) {
... ...
@@ -153,7 +176,7 @@ int tcp_http11_continue(struct tcp_connection *c)
153 153
 		}
154 154
 	}
155 155
 	/* check for Transfer-Encoding header */
156
-	if(strstr(c->req.start, "Transfer-Encoding: chunked")!=NULL)
156
+	if(strfindcasestrz(&msg, "Transfer-Encoding: chunked")!=NULL)
157 157
 	{
158 158
 		c->req.flags |= F_TCP_REQ_BCHUNKED;
159 159
 		ret = 1;