#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
+#include <arpa/inet.h>
#include <ctype.h>
#include <sys/uio.h>
#include <netdb.h>
} else
return -1;
+ url_decode(url);
+
r->method = r->http.status;
r->url = url;
r->version = version;
setsockopt(conn.fd, SOL_SOCKET, SO_SNDTIMEO, (char *)&timeout, sizeof(timeout));
}
+ char ipstr[INET6_ADDRSTRLEN];
+
+ // deal with both IPv4 and IPv6:
+ if (conn.addr.sin_family == AF_INET) {
+ struct sockaddr_in *s = (struct sockaddr_in *)&conn.addr;
+ inet_ntop(AF_INET, &s->sin_addr, ipstr, sizeof(ipstr));
+ } else { // AF_INET6
+ struct sockaddr_in6 *s = (struct sockaddr_in6 *)&conn.addr;
+ inet_ntop(AF_INET6, &s->sin6_addr, ipstr, sizeof(ipstr));
+ }
+
// Default response
init_response(&rep, &conn);
rep.code = 500;
res = read_http(&req.http);
if (res == 0) {
+ if (s->debug > 0)
+ printf("%-15s \"%s\"\n", ipstr, req.http.status);
res = parse_request_status(&req);
if (res == 0) {
const struct ez_httphandler key = { .path = req.url };
if (handler && handler->mode == EZ_PATH_PREFIX && strncmp(req.url, handler->path, strlen(handler->path)) != 0)
handler = NULL;
- if (handler)
+ if (handler) {
+ if (s->debug > 0)
+ printf("%s %s\n", req.method, req.url);
+
quit = handler->fn(&req, &rep);
- else
+ } else
httpresponse_set_response(&rep, 404, "Missing");
} else
httpresponse_set_response(&rep, 400, "Invalid");