Skip to content

Commit

Permalink
connection: New api: get_method and get_method_str
Browse files Browse the repository at this point in the history
Signed-off-by: Jianhui Zhao <zhaojh329@gmail.com>
  • Loading branch information
zhaojh329 committed Jul 1, 2020
1 parent 8a9f299 commit 758b587
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 0 deletions.
1 change: 1 addition & 0 deletions example/example.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"));
Expand Down
12 changes: 12 additions & 0 deletions src/connection.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions src/connection.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 758b587

Please sign in to comment.