|
|
@ -3,11 +3,12 @@ |
|
|
|
|
|
|
|
|
|
|
|
using namespace i2p::http; |
|
|
|
using namespace i2p::http; |
|
|
|
|
|
|
|
|
|
|
|
int main(int argc, char *argv[]) { |
|
|
|
int main() { |
|
|
|
HTTPReq *req; |
|
|
|
HTTPReq *req; |
|
|
|
int ret = 0, len = 0; |
|
|
|
int ret = 0, len = 0; |
|
|
|
const char *buf; |
|
|
|
const char *buf; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* test: parsing request with body */ |
|
|
|
buf = |
|
|
|
buf = |
|
|
|
"GET / HTTP/1.0\r\n" |
|
|
|
"GET / HTTP/1.0\r\n" |
|
|
|
"User-Agent: curl/7.26.0\r\n" |
|
|
|
"User-Agent: curl/7.26.0\r\n" |
|
|
@ -31,6 +32,7 @@ int main(int argc, char *argv[]) { |
|
|
|
assert(req->headers.find("User-Agent")->second == "curl/7.26.0"); |
|
|
|
assert(req->headers.find("User-Agent")->second == "curl/7.26.0"); |
|
|
|
delete req; |
|
|
|
delete req; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* test: parsing request without body */ |
|
|
|
buf = |
|
|
|
buf = |
|
|
|
"GET / HTTP/1.0\r\n" |
|
|
|
"GET / HTTP/1.0\r\n" |
|
|
|
"\r\n"; |
|
|
|
"\r\n"; |
|
|
@ -44,6 +46,7 @@ int main(int argc, char *argv[]) { |
|
|
|
assert(req->headers.size() == 0); |
|
|
|
assert(req->headers.size() == 0); |
|
|
|
delete req; |
|
|
|
delete req; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* test: parsing request without body */ |
|
|
|
buf = |
|
|
|
buf = |
|
|
|
"GET / HTTP/1.1\r\n" |
|
|
|
"GET / HTTP/1.1\r\n" |
|
|
|
"\r\n"; |
|
|
|
"\r\n"; |
|
|
@ -52,6 +55,7 @@ int main(int argc, char *argv[]) { |
|
|
|
assert((ret = req->parse(buf, len)) == -1); /* no host header */ |
|
|
|
assert((ret = req->parse(buf, len)) == -1); /* no host header */ |
|
|
|
delete req; |
|
|
|
delete req; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* test: parsing incomplete request */ |
|
|
|
buf = |
|
|
|
buf = |
|
|
|
"GET / HTTP/1.0\r\n" |
|
|
|
"GET / HTTP/1.0\r\n" |
|
|
|
""; |
|
|
|
""; |
|
|
@ -60,6 +64,7 @@ int main(int argc, char *argv[]) { |
|
|
|
assert((ret = req->parse(buf, len)) == 0); /* request not completed */ |
|
|
|
assert((ret = req->parse(buf, len)) == 0); /* request not completed */ |
|
|
|
delete req; |
|
|
|
delete req; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* test: parsing slightly malformed request */ |
|
|
|
buf = |
|
|
|
buf = |
|
|
|
"GET http://inr.i2p HTTP/1.1\r\n" |
|
|
|
"GET http://inr.i2p HTTP/1.1\r\n" |
|
|
|
"Host: stats.i2p\r\n" |
|
|
|
"Host: stats.i2p\r\n" |
|
|
|