check for malformed HTTP response
This commit is contained in:
parent
f9908a788b
commit
cce4407d9d
|
@ -1,4 +1,4 @@
|
|||
/* $Id: minihttptestserver.c,v 1.23 2018/01/15 16:20:07 nanard Exp $ */
|
||||
/* $Id: minihttptestserver.c,v 1.25 2020/05/29 21:14:22 nanard Exp $ */
|
||||
/* Project : miniUPnP
|
||||
* Author : Thomas Bernard
|
||||
* Copyright (c) 2011-2018 Thomas Bernard
|
||||
|
@ -261,7 +261,7 @@ void build_favicon_content(unsigned char * p, size_t n)
|
|||
}
|
||||
|
||||
enum modes {
|
||||
MODE_INVALID, MODE_CHUNKED, MODE_ADDCRAP, MODE_NORMAL, MODE_FAVICON
|
||||
MODE_INVALID, MODE_CHUNKED, MODE_ADDCRAP, MODE_NORMAL, MODE_FAVICON, MODE_MALFORMED
|
||||
};
|
||||
|
||||
const struct {
|
||||
|
@ -272,6 +272,7 @@ const struct {
|
|||
{MODE_ADDCRAP, "addcrap"},
|
||||
{MODE_NORMAL, "normal"},
|
||||
{MODE_FAVICON, "favicon.ico"},
|
||||
{MODE_MALFORMED, "malformed"},
|
||||
{MODE_INVALID, NULL}
|
||||
};
|
||||
|
||||
|
@ -413,6 +414,20 @@ void handle_http_connection(int c)
|
|||
}
|
||||
|
||||
switch(mode) {
|
||||
case MODE_MALFORMED:
|
||||
response_len = 2048;
|
||||
response_buffer = malloc(response_len);
|
||||
if(!response_buffer)
|
||||
break;
|
||||
n = snprintf(response_buffer, response_len,
|
||||
"HTTP/1.1 \r\n"
|
||||
"\r\n"
|
||||
/*"0000\r\n"*/);
|
||||
for (i = n; i < response_len; i++) {
|
||||
response_buffer[i] = ' ';
|
||||
}
|
||||
response_len = n;
|
||||
break;
|
||||
case MODE_CHUNKED:
|
||||
response_buffer = build_chunked_response(content_length, &response_len);
|
||||
break;
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
#!/bin/sh
|
||||
# $Id: testminiwget.sh,v 1.15 2017/11/02 17:36:26 nanard Exp $
|
||||
# $Id: testminiwget.sh,v 1.18 2020/05/29 21:14:22 nanard Exp $
|
||||
# vim: tabstop=4 shiftwidth=4 noexpandtab
|
||||
# project miniupnp : http://miniupnp.free.fr/
|
||||
# (c) 2011-2019 Thomas Bernard
|
||||
|
@ -71,6 +71,7 @@ echo "Test HTTP server is listening on $PORT"
|
|||
URL1="http://$ADDR:$PORT/index.html"
|
||||
URL2="http://$ADDR:$PORT/chunked"
|
||||
URL3="http://$ADDR:$PORT/addcrap"
|
||||
URL4="http://$ADDR:$PORT/malformed"
|
||||
|
||||
echo "standard test ..."
|
||||
./testminiwget $URL1 "${DOWNLOADEDFILE}.1"
|
||||
|
@ -99,6 +100,9 @@ else
|
|||
RET=1
|
||||
fi
|
||||
|
||||
echo "malformed response test ..."
|
||||
./testminiwget $URL4 "${DOWNLOADEDFILE}.4"
|
||||
|
||||
# kill the test HTTP server
|
||||
kill $SERVERPID
|
||||
wait $SERVERPID
|
||||
|
|
Loading…
Reference in New Issue