feat: Preliminary routes

master
Sean McBride 3 years ago
parent eb2ba85760
commit 6965b2906d

@ -30,6 +30,12 @@
"Connection: close\r\n" \
"\r\n"
#define HTTP_RESPONSE_404_NOT_FOUND \
"HTTP/1.1 404 Not Found\r\n" \
"Server: SLEdge\r\n" \
"Connection: close\r\n" \
"\r\n"
#define HTTP_RESPONSE_413_PAYLOAD_TOO_LARGE \
"HTTP/1.1 413 Payload Too Large\r\n" \
"Server: SLEdge\r\n" \
@ -70,6 +76,10 @@ http_header_build(int status_code)
response = HTTP_RESPONSE_400_BAD_REQUEST;
http_total_increment_4XX();
break;
case 404:
response = HTTP_RESPONSE_404_NOT_FOUND;
http_total_increment_4XX();
break;
case 413:
response = HTTP_RESPONSE_413_PAYLOAD_TOO_LARGE;
http_total_increment_4XX();
@ -99,6 +109,8 @@ http_header_len(int status_code)
switch (status_code) {
case 400:
return strlen(HTTP_RESPONSE_400_BAD_REQUEST);
case 404:
return strlen(HTTP_RESPONSE_404_NOT_FOUND);
case 413:
return strlen(HTTP_RESPONSE_413_PAYLOAD_TOO_LARGE);
case 429:

@ -21,6 +21,7 @@ enum
module_name,
module_path,
module_port,
module_route,
module_expected_execution_us,
module_admissions_percentile,
module_relative_deadline_us,
@ -33,6 +34,7 @@ enum
static const char *module_keys[module_keys_len] = { "name",
"path",
"port",
"route",
"expected-execution-us",
"admissions-percentile",
"relative-deadline-us",
@ -248,6 +250,11 @@ parse_json(const char *json_buf, ssize_t json_buf_size, struct module_config **m
int rc = parse_uint16_t(tokens[i], json_buf, module_keys[module_port],
&(*module_config_vec)[module_idx].port);
if (rc < 0) goto json_parse_err;
} else if (strcmp(key, module_keys[module_route]) == 0) {
if (!is_nonempty_string(tokens[i], key)) goto json_parse_err;
(*module_config_vec)[module_idx].route = strndup(json_buf + tokens[i].start,
tokens[i].end - tokens[i].start);
} else if (strcmp(key, module_keys[module_expected_execution_us]) == 0) {
if (!has_valid_type(tokens[i], key, JSMN_PRIMITIVE)) goto json_parse_err;

@ -21,8 +21,9 @@
#define MODULE_DEFAULT_REQUEST_RESPONSE_SIZE (PAGE_SIZE)
#define MODULE_MAX_NAME_LENGTH 32
#define MODULE_MAX_PATH_LENGTH 256
#define MODULE_MAX_NAME_LENGTH 32
#define MODULE_MAX_PATH_LENGTH 256
#define MODULE_MAX_ROUTE_LENGTH 256
extern thread_local int worker_thread_idx;
@ -56,6 +57,7 @@ struct module {
/* Metadata from JSON Config */
char name[MODULE_MAX_NAME_LENGTH];
char path[MODULE_MAX_PATH_LENGTH];
char route[MODULE_MAX_ROUTE_LENGTH];
uint32_t stack_size; /* a specification? */
uint32_t relative_deadline_us;
uint16_t port;

@ -7,6 +7,7 @@
struct module_config {
char *name;
char *path;
char *route;
uint16_t port;
uint8_t admissions_percentile;
uint32_t expected_execution_us;

@ -184,6 +184,13 @@ listener_thread_main(void *dummy)
continue;
}
if (strncmp(session->http_request.full_url, module->route, strlen(module->route))
!= 0) {
http_session_send_err_oneshot(session, 404);
http_session_close(session);
continue;
}
http_request_print(&session->http_request);
/*

@ -44,6 +44,9 @@ module_init(struct module *module, struct module_config *config)
panic("response-size must be between 0 and %u, was %u\n", (uint32_t)RUNTIME_HTTP_RESPONSE_SIZE_MAX,
config->http_resp_size);
/* If a route is not specified, default to root */
if (config->route == NULL) config->route = "/";
struct module *existing_module = module_database_find_by_name(config->name);
if (existing_module != NULL) panic("Module %s is already initialized\n", existing_module->name);
@ -86,6 +89,7 @@ module_init(struct module *module, struct module_config *config)
/* Set fields in the module struct */
strncpy(module->name, config->name, MODULE_MAX_NAME_LENGTH);
strncpy(module->path, config->path, MODULE_MAX_PATH_LENGTH);
strncpy(module->route, config->route, MODULE_MAX_ROUTE_LENGTH);
strncpy(module->response_content_type, config->http_resp_content_type, HTTP_MAX_HEADER_VALUE_LENGTH);
module->stack_size = ((uint32_t)(round_up_to_page(stack_size == 0 ? WASM_STACK_SIZE : stack_size)));

@ -1,8 +1,9 @@
[
{
"name": "fibonacci_10",
"name": "fibonacci",
"path": "fibonacci.wasm.so",
"port": 10010,
"route": "/fib",
"expected-execution-us": 6000,
"admissions-percentile": 70,
"relative-deadline-us": 20000,
@ -14,6 +15,7 @@
"name": "fibonacci_40",
"path": "fibonacci.wasm.so",
"port": 10040,
"route": "/fib",
"expected-execution-us": 10000000,
"admissions-percentile": 70,
"relative-deadline-us": 20000000,

@ -37,16 +37,16 @@ client:
http :1337
browser-args:
xdg-open "http://localhost:1337"
xdg-open "http://localhost:1337/index.html"
client-stdin:
echo "Example STDIN" | http :1337
client-args:
http ":1337?firstArg&secondArg&thirdArg"
http ":1337/index.html?firstArg&secondArg&thirdArg"
browser-args:
xdg-open "http://localhost:1337?firstArg&secondArg&thirdArg"
xdg-open "http://localhost:1337/index.html?firstArg&secondArg&thirdArg"
client-stdin-args:
echo "Example STDIN" | http ":1337?firstArg&secondArg&thirdArg"
echo "Example STDIN" | http ":1337/index.html?firstArg&secondArg&thirdArg"

@ -3,6 +3,7 @@
"name": "html",
"path": "html.wasm.so",
"port": 1337,
"route": "/index.html",
"expected-execution-us": 10000000,
"admissions-percentile": 70,
"relative-deadline-us": 20000000,

Loading…
Cancel
Save