Skip to content

Commit

Permalink
Add failing HttpParser test
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex Hultman authored and Alex Hultman committed Apr 20, 2022
1 parent 08a6785 commit 88b1cb1
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
37 changes: 37 additions & 0 deletions tests/HttpParser.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#include <iostream>
#include <cassert>

#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;

}
2 changes: 2 additions & 0 deletions tests/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 88b1cb1

Please sign in to comment.