diff --git a/example/example.c b/example/example.c index 9335969..d32194b 100644 --- a/example/example.c +++ b/example/example.c @@ -36,6 +36,7 @@ static void on_request(struct uh_connection *conn) conn->send_head(conn, 200, -1, NULL); conn->chunk_printf(conn, "I'm Libuhttpd: %s\n", UHTTPD_VERSION_STRING); + conn->chunk_printf(conn, "Method: %s\n", conn->get_method_str(conn)); conn->chunk_printf(conn, "Path: %s\n", conn->get_path(conn)); conn->chunk_printf(conn, "Query: %s\n", conn->get_query(conn)); conn->chunk_printf(conn, "User-Agent: %s\n", conn->get_header(conn, "User-Agent")); diff --git a/src/connection.c b/src/connection.c index ff83c77..cb66cb6 100644 --- a/src/connection.c +++ b/src/connection.c @@ -158,6 +158,16 @@ static void conn_redirect(struct uh_connection *conn, int code, const char *loca conn_send(conn, "\r\n", 2); } +static enum http_method conn_get_method(struct uh_connection *conn) +{ + return conn->parser.method; +} + +static const char *conn_get_method_str(struct uh_connection *conn) +{ + return http_method_str(conn->parser.method); +} + /* offset of the request field */ #define ROF(c, a) (a - (const char *)c->rb.data) @@ -569,6 +579,8 @@ struct uh_connection *uh_new_connection(struct uh_server *srv, int sock, struct conn->chunk_vprintf = conn_chunk_vprintf; conn->chunk_end = conn_chunk_end; + conn->get_method = conn_get_method; + conn->get_method_str = conn_get_method_str; conn->get_path = conn_get_path; conn->get_query = conn_get_query; conn->get_header = conn_get_header; diff --git a/src/connection.h b/src/connection.h index 7bbe95f..04c51be 100644 --- a/src/connection.h +++ b/src/connection.h @@ -101,6 +101,8 @@ struct uh_connection { void (*chunk_printf)(struct uh_connection *conn, const char *format, ...); void (*chunk_vprintf)(struct uh_connection *conn, const char *format, va_list arg); void (*chunk_end)(struct uh_connection *conn); + enum http_method (*get_method)(struct uh_connection *conn); + const char *(*get_method_str)(struct uh_connection *conn); const char *(*get_path)(struct uh_connection *conn); const char *(*get_query)(struct uh_connection *conn); const char *(*get_header)(struct uh_connection *conn, const char *name);