May 2019
Intermediate to advanced
478 pages
11h 21m
English
In the case where a client sends an HTTP request which our server does not understand, it is helpful to send a code 400 error. Because errors of this type can arise in several situations, we wrap this functionality in the send_400() function. The entire function follows:
/*web_server.c except*/void send_400(struct client_info *client) { const char *c400 = "HTTP/1.1 400 Bad Request\r\n" "Connection: close\r\n" "Content-Length: 11\r\n\r\nBad Request"; send(client->socket, c400, strlen(c400), 0); drop_client(client);}
The send_400() function first declares a text array with the entire HTTP response hard-coded. This text is sent using the send() function, and then the client is dropped by calling the drop_client() function we defined ...
Read now
Unlock full access