From f213b963cdd9084f07a3a7591e69b9067062c43a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20=C3=96man?= Date: Fri, 7 Dec 2007 08:24:48 +0000 Subject: [PATCH] Add HTTP redirect reply --- http.c | 29 ++++++++++++++++++++++++++++- http.h | 4 +++- 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/http.c b/http.c index 58b75bad..91e5a252 100644 --- a/http.c +++ b/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 "); + + 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) diff --git a/http.h b/http.h index 4cd6ce57..69f92ed6 100644 --- a/http.h +++ b/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);