diff --git a/lib/libwebsockets.h b/lib/libwebsockets.h index 2a9e92a3..1620d8ed 100644 --- a/lib/libwebsockets.h +++ b/lib/libwebsockets.h @@ -4520,7 +4520,7 @@ lws_return_http_status(struct lws *wsi, unsigned int code, const char *html_body); /** - * lws_http_redirect() - write http redirect into buffer + * lws_http_redirect() - write http redirect out on wsi * * \param wsi: websocket connection * \param code: HTTP response code (eg, 301) @@ -4528,6 +4528,8 @@ lws_return_http_status(struct lws *wsi, unsigned int code, * \param len: length of loc * \param p: pointer current position in buffer (updated as we write) * \param end: pointer to end of buffer + * + * Returns amount written, or < 0 indicating fatal write failure. */ LWS_VISIBLE LWS_EXTERN int LWS_WARN_UNUSED_RESULT lws_http_redirect(struct lws *wsi, int code, const unsigned char *loc, int len, diff --git a/minimal-examples/http-server/minimal-http-server-form-post-file/minimal-http-server-form-post-file.c b/minimal-examples/http-server/minimal-http-server-form-post-file/minimal-http-server-form-post-file.c index e974821b..a819e3f9 100644 --- a/minimal-examples/http-server/minimal-http-server-form-post-file/minimal-http-server-form-post-file.c +++ b/minimal-examples/http-server/minimal-http-server-form-post-file/minimal-http-server-form-post-file.c @@ -162,18 +162,7 @@ callback_http(struct lws *wsi, enum lws_callback_reasons reason, void *user, if (lws_http_redirect(wsi, HTTP_STATUS_MOVED_PERMANENTLY, (unsigned char *)"after-form1.html", - 16, &p, end)) - return -1; - - /* we could add more headers here */ - - if (lws_finalize_http_header(wsi, &p, end)) - return -1; - - n = lws_write(wsi, start, lws_ptr_diff(p, start), - LWS_WRITE_HTTP_HEADERS | - LWS_WRITE_H2_STREAM_END); - if (n < 0) + 16, &p, end) < 0) return -1; break; diff --git a/minimal-examples/http-server/minimal-http-server-form-post/minimal-http-server-form-post.c b/minimal-examples/http-server/minimal-http-server-form-post/minimal-http-server-form-post.c index 10c73e90..2f50863a 100644 --- a/minimal-examples/http-server/minimal-http-server-form-post/minimal-http-server-form-post.c +++ b/minimal-examples/http-server/minimal-http-server-form-post/minimal-http-server-form-post.c @@ -106,20 +106,8 @@ callback_http(struct lws *wsi, enum lws_callback_reasons reason, void *user, if (lws_http_redirect(wsi, HTTP_STATUS_MOVED_PERMANENTLY, (unsigned char *)"after-form1.html", - 16, &p, end)) + 16, &p, end) < 0) return -1; - - /* we could add more headers here */ - - if (lws_finalize_http_header(wsi, &p, end)) - return -1; - - n = lws_write(wsi, start, lws_ptr_diff(p, start), - LWS_WRITE_HTTP_HEADERS | - LWS_WRITE_H2_STREAM_END); - if (n < 0) - return -1; - break; case LWS_CALLBACK_HTTP_DROP_PROTOCOL: