From 76ae7c28ea6224b2c919122d5dc71bcc00a0ecaa Mon Sep 17 00:00:00 2001 From: yum Date: Mon, 3 Jul 2023 18:44:43 -0700 Subject: Begin work on proxy server Create a simple server with 3 endpoints: * /create_session: Create a session and return its identifier. * /set_transcript: Update a session's transcript. * /get_transcript: Fetch a session's transcript. Right now the session ID provides authentication *and* authorization. There is no public/private ID so you have to trust whoever you share your ID with. IDs are long and generated by the server, so it should be somewhat secure against low-effort hacking. Other updates: * Drop whisper_requirements.txt - no longer needed. * Vendor curl to make it easier to interact with the server. TODO: * Fuzz test the server. --- BrowserSource/Proxy/HTTPParser.h | 52 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 BrowserSource/Proxy/HTTPParser.h (limited to 'BrowserSource/Proxy/HTTPParser.h') diff --git a/BrowserSource/Proxy/HTTPParser.h b/BrowserSource/Proxy/HTTPParser.h new file mode 100644 index 0000000..e97f896 --- /dev/null +++ b/BrowserSource/Proxy/HTTPParser.h @@ -0,0 +1,52 @@ +#pragma once + +#include +#include +#include + +namespace WebServer { + + // A simple HTTP/1.1 message parser based on RFC 2616. + class HTTPParser + { + public: + HTTPParser(); + + bool Parse(const std::string& raw_http, std::string& err); + + const std::string& GetMethod() const; + const std::string& GetPath() const; + bool GetHeader(const std::string& header, std::string& value) const; + const std::map& GetHeaders() const; + const std::string& GetPayload() const; + + private: + enum ParserState { + PARSER_STATE_START_LINE, + PARSER_STATE_HEADERS, + PARSER_STATE_PAYLOAD, + }; + + bool ParseSegment( + const std::string_view segment, + ParserState& state, + std::string& err); + bool ParseStartLine( + const std::string_view segment, + ParserState& state, + std::string& err); + bool ParseHeaders( + const std::string_view segment, + ParserState& state, + std::string& err); + bool ParsePayload( + const std::string_view segment, + ParserState& state, + std::string& err); + + std::string method_; + std::string path_; + std::map headers_; + std::string payload_; + }; +} -- cgit v1.2.3