Exchange

Types

type http_state

Enum type used to track HTTP exchange parse state.

Definition
YMO_ENUM8_TYPEDEF(http_state) {
    HTTP_STATE_CONNECTED,
    HTTP_STATE_REQUEST_METHOD,
    HTTP_STATE_REQUEST_URI_PATH,
    HTTP_STATE_REQUEST_QUERY,
    HTTP_STATE_REQUEST_FRAGMENT,
    HTTP_STATE_REQUEST_VERSION,
    HTTP_STATE_CRLF,
    HTTP_STATE_HEADER_NAME,
    HTTP_STATE_HEADER_VALUE_LEADING_SPACE,
    HTTP_STATE_HEADER_VALUE,
    HTTP_STATE_HEADERS_COMPLETE,
    HTTP_STATE_EXPECT,
    HTTP_STATE_BODY_CHUNK_HEADER,
    HTTP_STATE_BODY,
    HTTP_STATE_BODY_CHUNK_TRAILER,
    HTTP_STATE_COMPLETE,
} YMO_ENUM8_AS(http_state_t);
type crlf_state

Enum type used to track HTTP end of line state.

Definition
YMO_ENUM8_TYPEDEF(crlf_state) {
    HTTP_EXPECT_CRLF,
    HTTP_EXPECT_LF,
} YMO_ENUM8_AS(crlf_state_t);
struct ymo_http_exchange

Struct used to store HTTP exchange data.

Todo

Move parse info stuff to separate struct and move to ymo_http_parse.

Definition
struct ymo_http_exchange {
    /* Request: */
    struct ymo_http_request  request;

    /* Parse info: */
    union {
        /* These are used for mutually exclusive parse phases: */
        struct {
            char*              hdr_name;
            char*              hdr_value;
            ymo_http_hdr_id_t  h_id;
        };
        size_t  body_remain;
    };

    http_state_t  state;
    http_state_t  next_state;
    char*         recv_current;
    size_t        remain;
    char          recv_buf[YMO_HTTP_RECV_BUF_SIZE];

    /* Response:
     *
     * (TODO: just add this to the exchange and skip the malloc/free).
     */
    ymo_http_response_t* response;
};

Functions

ymo_http_exchange_t *ymo_http_exchange_create(void)

Create a new http exchange object.

Returns

pointer to a new exchange, or NULL on failure.

void ymo_http_exchange_reset(ymo_http_exchange_t *exchange)

Reset an HTTP exchange struct to handle a new incoming exchange

void ymo_http_exchange_free(ymo_http_exchange_t *exchange)

Free an http exchange object.

Parameters
  • exchange – exchange to free

ymo_http_flags_t ymo_http_request_flags(const ymo_http_exchange_t *exchange)

Used to get common HTTP exchange traits

Parameters
  • exchange – the HTTP exchange instance to query

Returns

ymo_http_flags_t type indicating exchange traits