summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorJoel Klinghed <the_jk@yahoo.com>2017-08-06 22:23:41 +0200
committerJoel Klinghed <the_jk@yahoo.com>2017-08-06 22:25:44 +0200
commit178bb3a1ceab88f29aa7d0ceb453e76de172fd27 (patch)
tree09f830338d5490552ae878152de0f104cb7f6e5b /test
parent9d586aec3a5615377e389318e97e7d756c970c96 (diff)
Add protools, used for getting content out of packages
Only HTTP protocol implemented yet, but with gzip, deflate and bzip2 suport
Diffstat (limited to 'test')
-rw-r--r--test/test-http.cc60
1 files changed, 60 insertions, 0 deletions
diff --git a/test/test-http.cc b/test/test-http.cc
index 4b1b62f..73f5261 100644
--- a/test/test-http.cc
+++ b/test/test-http.cc
@@ -326,6 +326,38 @@ bool resp(std::string const& name, std::string const& out,
return true;
}
+bool tokens(std::string const& in, char const* header, ...) {
+ std::unique_ptr<HttpResponse> resp(HttpResponse::parse(in));
+ if (!resp) {
+ std::cerr << "tokens:" << header << ": Expected valid http" << std::endl;
+ return false;
+ }
+ auto iter = resp->header_tokens(header);
+ va_list tokens;
+ va_start(tokens, header);
+ while (true) {
+ auto token = va_arg(tokens, char const*);
+ if (!token) break;
+ if (!iter->valid()) {
+ std::cerr << "tokens:" << header << ": Expected " << token << " got "
+ << "no more tokens" << std::endl;
+ return false;
+ }
+ if (iter->token().compare(token)) {
+ std::cerr << "tokens:" << header << ": Expected " << token << " got "
+ << iter->token() << std::endl;
+ return false;
+ }
+ iter->next();
+ }
+ if (iter->valid()) {
+ std::cerr << "tokens:" << header << ": Expected no more tokens got "
+ << iter->token() << std::endl;
+ return false;
+ }
+ return true;
+}
+
} // namespace
int main() {
@@ -473,5 +505,33 @@ int main() {
"connection", "close",
nullptr));
+ RUN(tokens("HTTP/1.1 200 OK\r\n"
+ "\r\n", "Transfer-Encoding", nullptr));
+ RUN(tokens("HTTP/1.1 200 OK\r\n"
+ "Transfer-Encoding: chunked\r\n"
+ "\r\n", "Transfer-Encoding", "chunked", nullptr));
+ RUN(tokens("HTTP/1.1 200 OK\r\n"
+ "Transfer-Encoding: chunked, stuff; param=foo\r\n"
+ "\r\n", "Transfer-Encoding", "chunked", "stuff", nullptr));
+ RUN(tokens("HTTP/1.1 200 OK\r\n"
+ "Transfer-Encoding: chunked, stuff; param=\"foo\"\r\n"
+ "\r\n", "Transfer-Encoding", "chunked", "stuff", nullptr));
+ RUN(tokens("HTTP/1.1 200 OK\r\n"
+ "Transfer-Encoding: chunked;param=\"\\\"\",stuff\r\n"
+ "\r\n", "Transfer-Encoding", "chunked", "stuff", nullptr));
+ RUN(tokens("HTTP/1.1 200 OK\r\n"
+ "Transfer-Encoding: chunked;p1;p2=p3;=p4, stuff\r\n"
+ "\r\n", "Transfer-Encoding", "chunked", "stuff", nullptr));
+ RUN(tokens("HTTP/1.1 200 OK\r\n"
+ "Transfer-Encoding: chunked,stuff\r\n"
+ "\r\n", "Transfer-Encoding", "chunked", "stuff", nullptr));
+ RUN(tokens("HTTP/1.1 200 OK\r\n"
+ "Transfer-Encoding: chunked\r\n"
+ "Transfer-Encoding: stuff\r\n"
+ "\r\n", "Transfer-Encoding", "chunked", "stuff", nullptr));
+ RUN(tokens("HTTP/1.1 200 OK\r\n"
+ "Content-Type: text/html; charset=utf-8\r\n"
+ "\r\n", "Content-Type", "text", nullptr));
+
AFTER;
}