Compare commits
No commits in common. "eb9157281b478b510e039a3eb8be41dfc64787cc" and "711eaa2bde0a8eabdd297e3b9ed31f1a65792ee3" have entirely different histories.
eb9157281b
...
711eaa2bde
|
|
@ -32,9 +32,7 @@ typedef enum http_route_type {
|
|||
* before the step can finish its processing. For response steps, `false` means
|
||||
* there's new data in the write buffer that needs to be written.
|
||||
*/
|
||||
typedef bool (*http_step)(event_loop_conn *conn);
|
||||
|
||||
extern const http_step http_default_res_steps[HTTP_LOOP_MAX_STEPS];
|
||||
typedef bool (*step)(event_loop_conn *conn);
|
||||
|
||||
/**
|
||||
* Struct describing a route a request can take.
|
||||
|
|
@ -46,8 +44,8 @@ typedef struct http_route {
|
|||
// Compiled regex for a regex route. This value gets set at runtime when
|
||||
// starting the http loop
|
||||
regex_t *regex;
|
||||
const http_step steps[HTTP_LOOP_MAX_STEPS];
|
||||
const http_step steps_res[HTTP_LOOP_MAX_STEPS];
|
||||
step steps[HTTP_LOOP_MAX_STEPS];
|
||||
step steps_res[HTTP_LOOP_MAX_STEPS];
|
||||
} http_route;
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -4,9 +4,6 @@
|
|||
#include "http_loop.h"
|
||||
#include "log.h"
|
||||
|
||||
const http_step http_default_res_steps[HTTP_LOOP_MAX_STEPS] = {
|
||||
http_loop_step_write_header, http_loop_step_write_body, NULL};
|
||||
|
||||
bool http_loop_handle_request(event_loop_conn *conn) {
|
||||
// Prevents the request handler function from looping indefinitely without
|
||||
// ever consuming new data
|
||||
|
|
|
|||
|
|
@ -105,12 +105,9 @@ bool http_loop_step_write_body(event_loop_conn *conn) {
|
|||
void http_loop_handle_response(event_loop_conn *conn) {
|
||||
http_loop_ctx *ctx = conn->ctx;
|
||||
|
||||
// Non-routed requests also need to be processed
|
||||
const http_step *steps =
|
||||
ctx->route != NULL ? ctx->route->steps_res : http_default_res_steps;
|
||||
|
||||
while ((conn->state == event_loop_conn_state_res) &&
|
||||
(steps[ctx->current_step] != NULL) && steps[ctx->current_step](conn)) {
|
||||
(ctx->route->steps_res[ctx->current_step] != NULL) &&
|
||||
ctx->route->steps_res[ctx->current_step](conn)) {
|
||||
ctx->current_step++;
|
||||
}
|
||||
|
||||
|
|
@ -118,7 +115,7 @@ void http_loop_handle_response(event_loop_conn *conn) {
|
|||
// After response processing has finished its work, we reset the context to
|
||||
// prepare for a new request
|
||||
if ((conn->state != event_loop_conn_state_res) ||
|
||||
(steps[ctx->current_step] == NULL)) {
|
||||
(ctx->route->steps_res[ctx->current_step] == NULL)) {
|
||||
http_loop_ctx_reset(ctx);
|
||||
|
||||
conn->state = event_loop_conn_state_req;
|
||||
|
|
|
|||
Loading…
Reference in New Issue