aboutsummaryrefslogtreecommitdiff
path: root/src/net
diff options
context:
space:
mode:
Diffstat (limited to 'src/net')
-rw-r--r--src/net/util.c13
-rw-r--r--src/net/util.h2
2 files changed, 15 insertions, 0 deletions
diff --git a/src/net/util.c b/src/net/util.c
index 44a525b..150b8f9 100644
--- a/src/net/util.c
+++ b/src/net/util.c
@@ -63,6 +63,7 @@ int64_t recv_full_buffer(int client_fd, char** _buffer, int* header_eof, int* st
return len;
}
+#define max_uri_len 2048
/**
* @brief converts the request buffer into a parray_t
*
@@ -85,6 +86,11 @@ int parse_header(char* buffer, int header_eof, parray_t** _table){
item++;
if(buffer[oi] == '\n') break;
} else {
+ if(oi >= max_uri_len){
+ *_table = table;
+ str_free(current);
+ return -2;
+ }
str_pushl(current, buffer + oi, 1);
}
}
@@ -418,3 +424,10 @@ void parse_mimetypes(){
//printf("done\n");
}
+
+int net_error(int fd, int code){
+ char out[512] = {0};
+ sprintf(out, "HTTP/1.1 %i %s\n\n", code, http_code(code));
+ send(fd, out, strlen(out), 0);
+ return 0;
+}
diff --git a/src/net/util.h b/src/net/util.h
index e592420..254cc32 100644
--- a/src/net/util.h
+++ b/src/net/util.h
@@ -53,3 +53,5 @@ parray_t* route_match(parray_t* paths, char* path, larray_t** params);
int match_param(char* path, char* match, parray_t* arr);
void parse_mimetypes();
+
+int net_error(int fd, int code);