Add HTTP redirect reply
This commit is contained in:
parent
2036062aa4
commit
f213b963cd
2 changed files with 31 additions and 2 deletions
29
http.c
29
http.c
|
@ -245,6 +245,33 @@ http_output_queue(http_connection_t *hc, tcp_queue_t *tq, const char *content,
|
|||
tcp_output_queue(&hc->hc_tcp_session, NULL, tq);
|
||||
}
|
||||
|
||||
/**
|
||||
* Send an HTTP REDIRECT
|
||||
*/
|
||||
int
|
||||
http_redirect(http_connection_t *hc, const char *location)
|
||||
{
|
||||
tcp_queue_t tq;
|
||||
|
||||
http_output_reply_header(hc, 303, 0);
|
||||
|
||||
if(hc->hc_version < HTTP_VERSION_1_0)
|
||||
return -1;
|
||||
|
||||
tcp_init_queue(&tq, -1);
|
||||
|
||||
tcp_qprintf(&tq, "Please follow <a href=\"%s\"\"></a>");
|
||||
|
||||
http_printf(hc,
|
||||
"Location: %s\r\n"
|
||||
"Content-Type: text/html\r\n"
|
||||
"Content-Length: %d\r\n"
|
||||
"\r\n", location, tq.tq_depth);
|
||||
tcp_output_queue(&hc->hc_tcp_session, NULL, &tq);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* HTTP GET
|
||||
*/
|
||||
|
@ -545,7 +572,7 @@ http_arg_flush(struct http_arg_list *list)
|
|||
* Find an argument associated with a connection
|
||||
*/
|
||||
char *
|
||||
http_arg_get(struct http_arg_list *list, char *name)
|
||||
http_arg_get(struct http_arg_list *list, const char *name)
|
||||
{
|
||||
http_arg_t *ra;
|
||||
LIST_FOREACH(ra, list, link)
|
||||
|
|
4
http.h
4
http.h
|
@ -89,7 +89,7 @@ void http_start(int port);
|
|||
|
||||
void http_arg_flush(struct http_arg_list *list);
|
||||
|
||||
char *http_arg_get(struct http_arg_list *list, char *name);
|
||||
char *http_arg_get(struct http_arg_list *list, const char *name);
|
||||
|
||||
void http_arg_set(struct http_arg_list *list, char *key, char *val);
|
||||
|
||||
|
@ -100,6 +100,8 @@ void http_error(http_connection_t *hc, int error);
|
|||
void http_output_queue(http_connection_t *hc, tcp_queue_t *tq,
|
||||
const char *content, int maxage);
|
||||
|
||||
int http_redirect(http_connection_t *hc, const char *location);
|
||||
|
||||
typedef int (http_callback_t)(http_connection_t *hc, const char *remain,
|
||||
void *opaque);
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue