pandemonium_engine/modules/web/http_server_simple/http_parser.h

82 lines
2.2 KiB
C++
Raw Normal View History

2022-06-30 21:22:42 +02:00
#ifndef HTTP_PARSER_H
#define HTTP_PARSER_H
2022-06-30 23:12:32 +02:00
#include "core/ustring.h"
2022-06-30 21:22:42 +02:00
#include "core/reference.h"
class SimpleWebServerRequest;
2022-07-01 01:03:23 +02:00
struct http_parser;
struct http_parser_settings;
2022-06-30 23:12:32 +02:00
2022-06-30 21:22:42 +02:00
class HTTPParser : public Reference {
2022-06-30 23:12:32 +02:00
GDCLASS(HTTPParser, Reference);
2022-06-30 21:22:42 +02:00
public:
2022-07-20 16:28:37 +02:00
enum HTTPRequestContentType {
REQUEST_CONTENT_URLENCODED = 0,
REQUEST_CONTENT_MULTIPART_FORM_DATA,
REQUEST_CONTENT_TEXT_PLAIN,
};
Ref<SimpleWebServerRequest>
get_next_request();
int get_request_count() const;
2022-06-30 23:12:32 +02:00
bool is_ready() const;
bool is_finished() const;
2022-06-30 23:12:32 +02:00
void reset();
//returns the index where processing was ended -> start of the next query if != data_length
int read_from_buffer(const char *p_buffer, const int p_data_length);
2022-06-30 21:22:42 +02:00
HTTPParser();
~HTTPParser();
protected:
static void _bind_methods();
2022-06-30 23:12:32 +02:00
String _partial_data;
Ref<SimpleWebServerRequest> _request;
Vector<Ref<SimpleWebServerRequest>> _requests;
2022-06-30 23:12:32 +02:00
bool _is_ready;
2022-07-01 01:03:23 +02:00
private:
String chr_len_to_str(const char *at, size_t length);
int on_message_begin();
int on_url(const char *at, size_t length);
int on_status(const char *at, size_t length);
int on_header_field(const char *at, size_t length);
int on_header_value(const char *at, size_t length);
int on_headers_complete();
int on_body(const char *at, size_t length);
int on_message_complete();
int on_chunk_header();
int on_chunk_complete();
static int _on_message_begin_cb(http_parser *parser);
static int _on_url_cb(http_parser *parser, const char *at, size_t length);
static int _on_status_cb(http_parser *parser, const char *at, size_t length);
static int _on_header_field_cb(http_parser *parser, const char *at, size_t length);
static int _on_header_value_cb(http_parser *parser, const char *at, size_t length);
static int _on_headers_complete_cb(http_parser *parser);
static int _on_body_cb(http_parser *parser, const char *at, size_t length);
static int _on_message_complete_cb(http_parser *parser);
static int _on_chunk_header_cb(http_parser *parser);
static int _on_chunk_complete_cb(http_parser *parser);
http_parser *parser;
http_parser_settings *settings;
2022-07-20 16:28:37 +02:00
HTTPRequestContentType _content_type;
String _multipart_boundary;
bool _in_header;
String _queued_header_field;
2022-06-30 21:22:42 +02:00
};
#endif