Merge branch 'cookie_jar' into refactoring
# Conflicts: # chttp.h # src/client.h
This commit is contained in:
+72
-18
@@ -10,6 +10,44 @@
|
||||
// self-pipe.
|
||||
#define HTTP_CLIENT_POLL_CAPACITY (HTTP_CLIENT_CAPACITY+1)
|
||||
|
||||
#ifndef HTTP_COOKIE_JAR_CAPACITY
|
||||
// Maximum number of cookies that can be associated to a
|
||||
// single client.
|
||||
#define HTTP_COOKIE_JAR_CAPACITY 128
|
||||
#endif
|
||||
|
||||
typedef struct {
|
||||
|
||||
// Cookie name and value
|
||||
HTTP_String name;
|
||||
HTTP_String value;
|
||||
|
||||
// If the "exact_domain" is true, the cookie
|
||||
// can only be sent to the exact domain referred
|
||||
// to by "domain" (which is never empty). If
|
||||
// "exact_domain" is false, then the cookie is
|
||||
// compatible with subdomains.
|
||||
bool exact_domain;
|
||||
HTTP_String domain;
|
||||
|
||||
// If "exact_path" is set, the cookie is only
|
||||
// compatible with requests to paths that match
|
||||
// "path" exactly. If "exact_path" is not set,
|
||||
// then any path that starts with "path" is
|
||||
// compatible with the cookie.
|
||||
bool exact_path;
|
||||
HTTP_String path;
|
||||
|
||||
// This cookie can only be sent over HTTPS
|
||||
bool secure;
|
||||
|
||||
} HTTP_CookieJarEntry;
|
||||
|
||||
typedef struct {
|
||||
int count;
|
||||
HTTP_CookieJarEntry items[HTTP_COOKIE_JAR_CAPACITY];
|
||||
} HTTP_CookieJar;
|
||||
|
||||
typedef enum {
|
||||
HTTP_CLIENT_CONN_FREE,
|
||||
HTTP_CLIENT_CONN_WAIT_LINE,
|
||||
@@ -35,17 +73,31 @@ typedef struct {
|
||||
// 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;
|
||||
|
||||
// Allocated copy of the URL string
|
||||
HTTP_String url_buffer;
|
||||
|
||||
// Parsed URL for connection establishment
|
||||
// All url.* pointers reference into url_buffer
|
||||
HTTP_URL url;
|
||||
|
||||
// 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;
|
||||
@@ -59,6 +111,9 @@ struct HTTP_Client {
|
||||
uint32_t input_buffer_limit;
|
||||
uint32_t output_buffer_limit;
|
||||
|
||||
// List of cookies created during this session
|
||||
HTTP_CookieJar cookie_jar;
|
||||
|
||||
// Array of connections. The counter contains the
|
||||
// number of structs such that state!=FREE.
|
||||
int num_conns;
|
||||
@@ -104,15 +159,14 @@ typedef struct {
|
||||
uint16_t gen;
|
||||
} HTTP_RequestBuilder;
|
||||
|
||||
// Create a new request builder object. If the response
|
||||
// pointer is NULL, a brand new builder is created. If
|
||||
// response isn't NULL (and http_free_response wasn't
|
||||
// called on it yet), the connection associated to that
|
||||
// previous exchange is reused. Note that it's up to the
|
||||
// user to make sure the requests are targeting the same
|
||||
// host. Returns 0 on success, -1 on error.
|
||||
int http_client_get_builder(HTTP_Client *client,
|
||||
HTTP_Response *response, HTTP_RequestBuilder *builder);
|
||||
// Create a new request builder object.
|
||||
HTTP_RequestBuilder http_client_get_builder(HTTP_Client *client);
|
||||
|
||||
// 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.
|
||||
@@ -148,11 +202,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