Skip to content

Commit b5bb097

Browse files
committed
Improve header check.
1 parent 278dd54 commit b5bb097

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

include/http.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ typedef struct _swHttpRequest
5353
uint8_t version;
5454
uint8_t opcode;
5555
uint8_t excepted;
56-
uint8_t keep_alive :1;
56+
uint8_t keep_alive;
5757

5858
uint32_t url_offset;
5959
uint32_t url_length;

src/protocol/Http.c

+5-2
Original file line numberDiff line numberDiff line change
@@ -205,13 +205,15 @@ void swHttpRequest_free(swConnection *conn)
205205
int swHttpRequest_get_header_info(swHttpRequest *request)
206206
{
207207
swString *buffer = request->buffer;
208+
// header field start
208209
char *buf = buffer->str + buffer->offset;
209210

210-
//point-end: start + strlen(header) without strlen("\r\n\r\n")
211-
char *pe = buf + request->header_length - 4;
211+
//point-end: start + strlen(all-header) without strlen("\r\n\r\n")
212+
char *pe = buffer->str + request->header_length - 4;
212213
char *p;
213214
uint8_t got_len = 0;
214215

216+
*(pe) = '\0';
215217
for (p = buf + 1; p < pe; p++)
216218
{
217219
if (*p == '\n' && *(p-1) == '\r')
@@ -245,6 +247,7 @@ int swHttpRequest_get_header_info(swHttpRequest *request)
245247
}
246248
}
247249
}
250+
*(pe) = '\r';
248251

249252
return got_len ? SW_OK: SW_ERR;
250253
}

0 commit comments

Comments
 (0)