added get request check
This commit is contained in:
parent
7d98124fbc
commit
d3c75b26fc
15
webserver.c
15
webserver.c
|
@ -1,7 +1,8 @@
|
|||
#include <arpa/inet.h>
|
||||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include <arpa/inet.h>
|
||||
#include <sys/socket.h>
|
||||
#include <unistd.h>
|
||||
|
||||
|
@ -77,6 +78,16 @@ int main() {
|
|||
sscanf(buffer, "%s %s %s", method, uri, version);
|
||||
printf("[%s:%u] %s %s %s\n", inet_ntoa(client_addr.sin_addr), ntohs(client_addr.sin_port), method, version, uri);
|
||||
|
||||
// check if request is GET request
|
||||
if (strncmp("GET", method, 7) != 0) {
|
||||
const char resp[] = "HTTP/1.0 400 Bad Request\r\n"
|
||||
"Server: webserver-c\r\n"
|
||||
"Content-type: text/html\r\n\r\n";
|
||||
write(newsockfd, resp, strlen(resp));
|
||||
} else {
|
||||
// TO DO: IMPLEMENT FILE READING
|
||||
}
|
||||
|
||||
// write to the socket
|
||||
int valwrite = write(newsockfd, resp, strlen(resp));
|
||||
if (valwrite < 0) {
|
||||
|
|
Loading…
Reference in New Issue