Http keep alive

This commit is contained in:
2020-12-11 23:03:54 +01:00
parent e116b940b2
commit f7fc4fa801
6 changed files with 89 additions and 13 deletions

View File

@ -6,3 +6,30 @@
*/
#include "http.h"
#include "utils.h"
int http_receive_request(sock *client, http_req *req) {
char *buf = malloc(CLIENT_MAX_HEADER_SIZE);
ssize_t len;
memset(buf, 0, CLIENT_MAX_HEADER_SIZE);
while (1) {
if (client->enc) {
len = SSL_read(client->ssl, buf, CLIENT_MAX_HEADER_SIZE);
if (len < 0) {
print(ERR_STR "Unable to receive: %s" CLR_STR, ssl_get_error(client->ssl, len));
continue;
}
} else {
len = recv(client->socket, buf, CLIENT_MAX_HEADER_SIZE, 0);
if (len < 0) {
print(ERR_STR "Unable to receive: %s" CLR_STR, strerror(errno));
continue;
}
}
break;
}
return 0;
}