Skip to content

Commit

Permalink
chore: improve log
Browse files Browse the repository at this point in the history
Signed-off-by: Jianhui Zhao <zhaojh329@gmail.com>
  • Loading branch information
zhaojh329 authored and gl-zhaojianhui committed Aug 31, 2021
1 parent 33cd544 commit 6c8244c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
14 changes: 7 additions & 7 deletions src/connection.c
Original file line number Diff line number Diff line change
Expand Up @@ -152,11 +152,17 @@ static inline void conn_end_headers(struct uh_connection *conn)
static void conn_send_head_v(struct uh_connection *conn, int code, int64_t content_length, const char *reason, va_list arg)
{
struct uh_connection_internal *conni = (struct uh_connection_internal *)conn;
const struct uh_str path = conn->get_path(conn);
struct buffer *wb = &conni->wb;
char addr_str[INET6_ADDRSTRLEN];
int port;

if (likely(!reason))
reason = http_status_str(code);

log_info("%s %d %s %.*s - %d %s\n", addr_str, (saddr2str(&conni->paddr.sa, addr_str, sizeof(addr_str), &port) ? port : 0),
http_method_str(conni->parser.method), (int)path.len, path.p, code, reason);

buffer_put_printf(wb, "HTTP/1.1 %d ", code);
buffer_put_vprintf(wb, reason, arg);
buffer_put_printf(wb, "\r\nServer: Libuhttpd/%s\r\n", UHTTPD_VERSION_STRING);
Expand Down Expand Up @@ -535,11 +541,8 @@ static int on_headers_complete(struct http_parser *parser)
struct uh_server_internal *srv = conn->l->srv;
struct http_parser_url *u = &conn->url_parser;
struct uh_request *req = &conn->req;
struct sockaddr *sa = &conn->paddr.sa;
uh_path_handler_prototype handler;
char addr_str[INET6_ADDRSTRLEN];
struct uh_str path;
int port;

canonpath((char *)O2D(conn, req->url.offset), &req->url.length);

Expand All @@ -548,9 +551,6 @@ static int on_headers_complete(struct http_parser *parser)
path.p = O2D(conn, u->field_data[UF_PATH].off) + req->url.offset;
path.len = u->field_data[UF_PATH].len;

log_info("%s %d %s %.*s\n", addr_str, (saddr2str(sa, addr_str, sizeof(addr_str), &port) ? port : 0),
http_method_str(parser->method), (int)path.len, path.p);

handler = find_path_handler(conn, &srv->handlers, &path);
if (!handler)
handler = find_plugin_handler(conn, &srv->plugins, &path);
Expand Down Expand Up @@ -677,7 +677,7 @@ void conn_free(struct uh_connection_internal *conn)

cgi_free(conn);

log_info("Connection(%s %d) closed\n", addr_str,
log_debug("Connection(%s %d) closed\n", addr_str,
(saddr2str(&conn->paddr.sa, addr_str, sizeof(addr_str), &port) ? port : 0));

conn_decref((struct uh_connection *)conn);
Expand Down
2 changes: 1 addition & 1 deletion src/uhttpd.c
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ static void uh_accept_cb(struct ev_loop *loop, struct ev_io *w, int revents)
return;
}

log_info("New Connection from %s %d\n", addr_str,
log_debug("New Connection from %s %d\n", addr_str,
(saddr2str(&addr.sa, addr_str, sizeof(addr_str), &port) ? port : 0));

if (l->ssl) {
Expand Down

0 comments on commit 6c8244c

Please sign in to comment.