connection: New api: get_method and get_method_str
Signed-off-by: Jianhui Zhao <zhaojh329@gmail.com>main
parent
8a9f29958f
commit
758b5875c2
|
@ -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"));
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue