Refactoring of the HTTP client
This commit is contained in:
+27
-15
@@ -59,26 +59,32 @@ typedef struct HTTP_Client HTTP_Client;
|
||||
typedef struct {
|
||||
HTTP_ClientConnState state;
|
||||
|
||||
// Handle to the socket
|
||||
SocketHandle handle;
|
||||
|
||||
// Pointer back to the client
|
||||
HTTP_Client *client;
|
||||
|
||||
// Generation counter for request builder validation
|
||||
uint16_t gen;
|
||||
|
||||
// Opaque pointer set by the user while building
|
||||
// the request. It's returned alongside the result.
|
||||
void *user;
|
||||
|
||||
// TODO: comment
|
||||
bool trace_bytes;
|
||||
|
||||
// Endpoint domain and path. These must be saved
|
||||
// in case the server wants to set some cookies.
|
||||
HTTP_String domain;
|
||||
HTTP_String path;
|
||||
|
||||
// Data received from the server
|
||||
ByteQueue input;
|
||||
|
||||
// Data being sent to the server
|
||||
ByteQueue output;
|
||||
|
||||
// HTTP method for the request
|
||||
HTTP_Method method;
|
||||
|
||||
// Parsed URL for connection establishment
|
||||
HTTP_URL url;
|
||||
// If the request is COMPLETE, indicates
|
||||
// whether it completed with an error (-1)
|
||||
// or a success (0). If it was a success,
|
||||
// the response field is valid.
|
||||
int result;
|
||||
|
||||
// Parsed response once complete
|
||||
HTTP_Response response;
|
||||
@@ -150,6 +156,12 @@ typedef struct {
|
||||
int http_client_get_builder(HTTP_Client *client,
|
||||
HTTP_Response *response, HTTP_RequestBuilder *builder);
|
||||
|
||||
// TODO: comment
|
||||
void http_request_builder_set_user(HTTP_RequestBuilder builder, void *user);
|
||||
|
||||
// TODO: comment
|
||||
void http_request_builder_set_trace_bytes(HTTP_RequestBuilder builder, bool trace_bytes);
|
||||
|
||||
// Set the method and URL of the current request. This is the first
|
||||
// function of the request builder that the user must call.
|
||||
void http_request_builder_url(HTTP_RequestBuilder builder,
|
||||
@@ -184,11 +196,11 @@ int http_client_process_events(HTTP_Client *client,
|
||||
// may be availabe. This function returns one of the
|
||||
// buffered responses. If a request was available, true
|
||||
// is returned. If no more are avaiable, false is returned.
|
||||
// The returned response must either be freed using the
|
||||
// http_free_response function or reused by passing it
|
||||
// to http_client_get_builder.
|
||||
// The returned response must be freed using the
|
||||
// http_free_response function.
|
||||
// TODO: Better comment talking about output arguments
|
||||
bool http_client_next_response(HTTP_Client *client,
|
||||
HTTP_Response **response);
|
||||
HTTP_Response **response, void **user);
|
||||
|
||||
// Free a response object. You can't access its fields
|
||||
// again after this.
|
||||
|
||||
Reference in New Issue
Block a user