From 88b1cb10e6c66224d0805d58f75be2008b308eb3 Mon Sep 17 00:00:00 2001 From: Alex Hultman Date: Wed, 20 Apr 2022 12:49:41 +0200 Subject: [PATCH] Add failing HttpParser test --- tests/HttpParser.cpp | 37 +++++++++++++++++++++++++++++++++++++ tests/Makefile | 2 ++ 2 files changed, 39 insertions(+) create mode 100644 tests/HttpParser.cpp diff --git a/tests/HttpParser.cpp b/tests/HttpParser.cpp new file mode 100644 index 0000000..c7342f7 --- /dev/null +++ b/tests/HttpParser.cpp @@ -0,0 +1,37 @@ +#include +#include + +#include "../src/HttpParser.h" + +int main() { + unsigned char data[] = {0x47, 0x45, 0x54, 0x20, 0x2f, 0x20, 0x48, 0x54, 0x54, 0x50, 0x2f, 0x31, 0x2e, 0x31, 0xd, 0xa, 0x61, 0x73, 0x63, 0x69, 0x69, 0x3a, 0x20, 0x74, 0x65, 0x73, 0x74, 0xd, 0xa, 0x75, 0x74, 0x66, 0x38, 0x3a, 0x20, 0xd1, 0x82, 0xd0, 0xb5, 0xd1, 0x81, 0xd1, 0x82, 0xd, 0xa, 0x48, 0x6f, 0x73, 0x74, 0x3a, 0x20, 0x31, 0x32, 0x37, 0x2e, 0x30, 0x2e, 0x30, 0x2e, 0x31, 0xd, 0xa, 0x43, 0x6f, 0x6e, 0x6e, 0x65, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x3a, 0x20, 0x63, 0x6c, 0x6f, 0x73, 0x65, 0xd, 0xa, 0xd, 0xa, 'E'}; + int size = sizeof(data) - 1; + void *user = nullptr; + void *reserved = nullptr; + + uWS::HttpParser httpParser; + + void *returnedUser = httpParser.consumePostPadded((char *) data, size, user, reserved, [reserved](void *s, uWS::HttpRequest *httpRequest) -> void * { + + std::cout << httpRequest->getMethod() << std::endl; + + // This fails on anything other than Linux? + assert(httpRequest->getHeader("utf8").length()); + + /* Return ok */ + return s; + + }, [](void *user, std::string_view data, bool fin) -> void * { + + /* Return ok */ + return user; + + }, [](void *user) -> void * { + + /* Return break */ + return nullptr; + }); + + std::cout << "HTTP DONE" << std::endl; + +} \ No newline at end of file diff --git a/tests/Makefile b/tests/Makefile index c846b03..93d72bb 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -7,3 +7,5 @@ default: ./BloomFilter $(CXX) -std=c++17 -fsanitize=address ExtensionsNegotiator.cpp -o ExtensionsNegotiator ./ExtensionsNegotiator + $(CXX) -std=c++17 -fsanitize=address HttpParser.cpp -o HttpParser + ./HttpParser \ No newline at end of file