diff --git a/src/http.c b/src/http.c index 2c08fae..ce76933 100644 --- a/src/http.c +++ b/src/http.c @@ -326,10 +326,48 @@ out: return success; } + +static int val_api_url(struct http_transaction *ta) { + char *req_path = bufio_offset2ptr(ta->client->bufio, ta->req_path); + if (!strcmp(req_path, "/api/login")) { + return 0; + } + if (!strcmp(req_path, "/api/video")) { + return 1; + } + return -1; + +} static bool handle_api(struct http_transaction *ta) { - return send_error(ta, HTTP_NOT_FOUND, "API not implemented"); + int val = val_api_url(ta); + + if (val == -1){ + return send_not_found(ta); + } + + http_add_header(&ta->resp_headers, "Accept-Ranges", "bytes"); + if (val == 0) { + if (ta->req_method == HTTP_POST) { + // Handle login post + } + + else if (ta->req_method == HTTP_GET){ + // Handle login get + } + + else{ + return send_error(ta, HTTP_METHOD_NOT_ALLOWED, "Unknown method.\n"); + } + + } + else { + // Handle video api + } + + return false; + } /* Set up an http client, associating it with a bufio buffer. */