feat: added http response type names
This commit is contained in:
parent
a90330dd6e
commit
590f0e5186
6 changed files with 168 additions and 21 deletions
|
|
@ -39,7 +39,7 @@ bool http_loop_handle_request(event_loop_conn *conn) {
|
|||
// It's fun to respond with extremely specific error messages
|
||||
// https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/501
|
||||
else if (res == http_parse_error_unknown_method) {
|
||||
http_write_standard_response(conn, 501);
|
||||
http_loop_write_standard_response(conn, 501);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -74,19 +74,18 @@ http_parse_error http_loop_parse_request(event_loop_conn *conn) {
|
|||
void http_loop_process_request(event_loop_conn *conn) {
|
||||
http_loop_ctx *ctx = conn->ctx;
|
||||
|
||||
// The end of the list of steps is marked with a NULL. When this is reached,
|
||||
// we simply set the route to NULL, letting the http loop know a new request
|
||||
// can be handled.
|
||||
// We keep processing step functions as long as they don't need to wait for
|
||||
// I/O
|
||||
while ((ctx->route->steps[ctx->current_step] != NULL) &&
|
||||
ctx->route->steps[ctx->current_step](conn)) {
|
||||
ctx->current_step++;
|
||||
}
|
||||
|
||||
// If we've reached the end of the list of step functions, we report the
|
||||
// request as finished by clearing its route
|
||||
if (ctx->route->steps[ctx->current_step] == NULL) {
|
||||
ctx->route = NULL;
|
||||
ctx->current_step = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
// We execute the next step
|
||||
// NOTE can/should we execute more than one step at once here?
|
||||
if (ctx->route->steps[ctx->current_step](conn)) {
|
||||
ctx->current_step++;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -114,7 +113,7 @@ bool http_loop_route_request(event_loop_conn *conn) {
|
|||
}
|
||||
|
||||
// Fallthrough is to write a 404
|
||||
http_write_standard_response(conn, http_not_found);
|
||||
http_loop_write_standard_response(conn, http_not_found);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
#include "http.h"
|
||||
#include "http_loop.h"
|
||||
#include "string.h"
|
||||
|
||||
void http_write_standard_response(event_loop_conn *conn,
|
||||
http_response_type type) {
|
||||
void http_loop_write_standard_response(event_loop_conn *conn,
|
||||
http_response_type type) {
|
||||
const char *s;
|
||||
size_t len;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue