refactor(http): change cws_http_s to cws_request_s
This commit is contained in:
@@ -43,7 +43,7 @@ static int cws_server_handle_client_data(int epfd, int client_fd) {
|
||||
return CWS_SERVER_CLIENT_DISCONNECTED_ERROR;
|
||||
}
|
||||
|
||||
cws_http_s *request = cws_http_parse(data);
|
||||
cws_request_s *request = cws_http_parse(data);
|
||||
string_free(data);
|
||||
if (request == NULL) {
|
||||
cws_server_close_client(epfd, client_fd);
|
||||
@@ -54,7 +54,7 @@ static int cws_server_handle_client_data(int epfd, int client_fd) {
|
||||
cws_http_send_response(request, HTTP_OK);
|
||||
|
||||
cws_http_free(request);
|
||||
// cws_server_close_client(epfd, client_fd);
|
||||
cws_server_close_client(epfd, client_fd);
|
||||
|
||||
return CWS_SERVER_OK;
|
||||
}
|
||||
|
||||
@@ -8,8 +8,8 @@
|
||||
#include "utils/debug.h"
|
||||
#include "utils/hash.h"
|
||||
|
||||
static cws_http_s *http_new() {
|
||||
cws_http_s *request = malloc(sizeof(cws_http_s));
|
||||
static cws_request_s *http_new() {
|
||||
cws_request_s *request = malloc(sizeof *request);
|
||||
if (!request) {
|
||||
return NULL;
|
||||
}
|
||||
@@ -34,7 +34,7 @@ static cws_http_method_e http_parse_method(const char *method) {
|
||||
return HTTP_UNKNOWN;
|
||||
}
|
||||
|
||||
static bool parse_method(cws_http_s *req, char **cursor) {
|
||||
static bool parse_method(cws_request_s *req, char **cursor) {
|
||||
char *s = *cursor + strspn(*cursor, " ");
|
||||
size_t len = strcspn(s, " ");
|
||||
if (len == 0 || s[len] == '\0') {
|
||||
@@ -49,7 +49,7 @@ static bool parse_method(cws_http_s *req, char **cursor) {
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool parse_location(cws_http_s *req, char **cursor) {
|
||||
static bool parse_location(cws_request_s *req, char **cursor) {
|
||||
char *s = *cursor + strspn(*cursor, " ");
|
||||
size_t len = strcspn(s, " ");
|
||||
if (len == 0 || s[len] == '\0') {
|
||||
@@ -64,7 +64,7 @@ static bool parse_location(cws_http_s *req, char **cursor) {
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool parse_version(cws_http_s *req, char **cursor) {
|
||||
static bool parse_version(cws_request_s *req, char **cursor) {
|
||||
char *s = *cursor + strspn(*cursor, " \t");
|
||||
size_t len = strcspn(s, "\r\n");
|
||||
if (len == 0 || s[len] == '\0') {
|
||||
@@ -79,7 +79,7 @@ static bool parse_version(cws_http_s *req, char **cursor) {
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool parse_headers(cws_http_s *req, char **cursor) {
|
||||
static bool parse_headers(cws_request_s *req, char **cursor) {
|
||||
req->headers =
|
||||
hm_new(my_str_hash_fn, my_str_equal_fn, my_str_free_fn, my_str_free_fn,
|
||||
sizeof(char) * CWS_HTTP_HEADER_MAX, sizeof(char) * CWS_HTTP_HEADER_CONTENT_MAX);
|
||||
@@ -125,12 +125,12 @@ static bool parse_headers(cws_http_s *req, char **cursor) {
|
||||
return true;
|
||||
}
|
||||
|
||||
cws_http_s *cws_http_parse(string_s *request_str) {
|
||||
cws_request_s *cws_http_parse(string_s *request_str) {
|
||||
if (!request_str || !request_str->data) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
cws_http_s *request = http_new();
|
||||
cws_request_s *request = http_new();
|
||||
if (!request) {
|
||||
return NULL;
|
||||
}
|
||||
@@ -173,7 +173,7 @@ cws_http_s *cws_http_parse(string_s *request_str) {
|
||||
return request;
|
||||
}
|
||||
|
||||
void cws_http_free(cws_http_s *request) {
|
||||
void cws_http_free(cws_request_s *request) {
|
||||
if (!request) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#include "http/response.h"
|
||||
|
||||
#include "http/mime.h"
|
||||
#include "http/request.h"
|
||||
#include "utils/debug.h"
|
||||
#include <core/socket.h>
|
||||
#include <errno.h>
|
||||
@@ -99,8 +100,7 @@ static size_t file_data(const char *path, char **data) {
|
||||
return content_length;
|
||||
}
|
||||
|
||||
static void http_send_resource(cws_http_s *request) {
|
||||
/* Retrieve correct Content-Type */
|
||||
static void http_send_resource(cws_request_s *request) {
|
||||
char content_type[CWS_HTTP_CONTENT_TYPE];
|
||||
http_get_content_type(request->location_path->data, content_type);
|
||||
|
||||
@@ -146,7 +146,7 @@ size_t http_response_builder(char **response, cws_http_status_e status, char *co
|
||||
return total_len;
|
||||
}
|
||||
|
||||
void cws_http_send_response(cws_http_s *request, cws_http_status_e status) {
|
||||
void cws_http_send_response(cws_request_s *request, cws_http_status_e status) {
|
||||
char *response = NULL;
|
||||
|
||||
switch (status) {
|
||||
|
||||
Reference in New Issue
Block a user