Project homepage Mailing List  Warmcat.com  API Docs  Github Mirror 
{"schema":"libjg2-1", "vpath":"/git/", "avatar":"/git/avatar/", "alang":"", "gen_ut":1756677296, "reponame":"libwebsockets", "desc":"libwebsockets lightweight C networking library", "owner": { "name": "Andy Green", "email": "andy@warmcat.com", "md5": "c50933ca2aa61e0fe2c43d46bb6b59cb" },"url":"https://libwebsockets.org/repo/libwebsockets", "f":3, "items": [ {"schema":"libjg2-1", "cid":"c0b8fe1aa6df8ec5ef4f09fcb0c3e132", "commit": {"type":"commit", "time": 1460722176, "time_ofs": 480, "oid_tree": { "oid": "fe8b73a55015c4f33cd0a7ede34ff65698c44f37", "alias": []}, "oid":{ "oid": "7e2c3851bf838bc5d0aaf5a8b64206761f3e3d0f", "alias": []}, "msg": "redirects need fake content metadata", "sig_commit": { "git_time": { "time": 1460722176, "offset": 480 }, "name": "Andy Green", "email": "andy@warmcat.com", "md5": "c50933ca2aa61e0fe2c43d46bb6b59cb" }, "sig_author": { "git_time": { "time": 1460722176, "offset": 480 }, "name": "Andy Green", "email": "andy@warmcat.com", "md5": "c50933ca2aa61e0fe2c43d46bb6b59cb" }}, "body": "redirects need fake content metadata\n\nChrome deals with it without on desktop, but Android chrome\nwaits for the connection to time out before actioning the\nredirect, since it feels there might be html payload coming.\n\nSigned-off-by: Andy Green \u003candy@warmcat.com\u003e" , "diff": "diff --git a/lib/header.c b/lib/header.c\nindex 457f544..70058d1 100644\n--- a/lib/header.c\n+++ b/lib/header.c\n@@ -250,3 +250,42 @@ lws_return_http_status(struct lws *wsi, unsigned int code,\n \n \treturn m !\u003d n;\n }\n+\n+LWS_VISIBLE int\n+lws_http_redirect(struct lws *wsi, const unsigned char *loc, int len,\n+\t\t unsigned char **p, unsigned char *end)\n+{\n+\tunsigned char *start \u003d *p;\n+\tint n;\n+\n+\tif (lws_add_http_header_status(wsi, 301, p, end))\n+\t\treturn -1;\n+\n+\tif (lws_add_http_header_by_token(wsi,\n+\t\t\tWSI_TOKEN_HTTP_LOCATION,\n+\t\t\tloc, len, p, end))\n+\t\treturn -1;\n+\t/*\n+\t * if we're going with http/1.1 and keepalive,\n+\t * we have to give fake content metadata so the\n+\t * client knows we completed the transaction and\n+\t * it can do the redirect...\n+\t */\n+\tif (lws_add_http_header_by_token(wsi,\n+\t\t\tWSI_TOKEN_HTTP_CONTENT_TYPE,\n+\t\t\t(unsigned char *)\u0022text/html\u0022, 9,\n+\t\t\tp, end))\n+\t\treturn -1;\n+\tif (lws_add_http_header_by_token(wsi,\n+\t\t\tWSI_TOKEN_HTTP_CONTENT_LENGTH,\n+\t\t\t(unsigned char *)\u00220\u0022, 1, p, end))\n+\t\treturn -1;\n+\n+\tif (lws_finalize_http_header(wsi, p, end))\n+\t\treturn -1;\n+\n+\tn \u003d lws_write(wsi, start, *p - start,\n+\t\t\tLWS_WRITE_HTTP_HEADERS);\n+\n+\treturn n;\n+}\ndiff --git a/lib/libwebsockets.h b/lib/libwebsockets.h\nindex 0d90c55..0f6687d 100644\n--- a/lib/libwebsockets.h\n+++ b/lib/libwebsockets.h\n@@ -1643,6 +1643,10 @@ lws_add_http_header_status(struct lws *wsi,\n \t\t\t unsigned int code, unsigned char **p,\n \t\t\t unsigned char *end);\n \n+LWS_VISIBLE LWS_EXTERN int\n+lws_http_redirect(struct lws *wsi, const unsigned char *loc, int len,\n+\t\t unsigned char **p, unsigned char *end);\n+\n LWS_VISIBLE LWS_EXTERN int LWS_WARN_UNUSED_RESULT\n lws_http_transaction_completed(struct lws *wsi);\n \ndiff --git a/lib/server.c b/lib/server.c\nindex 880cc4a..fc11a74 100644\n--- a/lib/server.c\n+++ b/lib/server.c\n@@ -424,7 +424,6 @@ lws_http_action(struct lws *wsi)\n \tlws_set_timeout(wsi, PENDING_TIMEOUT_HTTP_CONTENT,\n \t\t\twsi-\u003econtext-\u003etimeout_secs);\n #ifdef LWS_OPENSSL_SUPPORT\n-#if 0\n \tif (wsi-\u003eredirect_to_https) {\n \t\t/*\n \t\t * we accepted http:// only so we could redirect to\n@@ -436,23 +435,17 @@ lws_http_action(struct lws *wsi)\n \n \t\tif (!lws_hdr_total_length(wsi, WSI_TOKEN_HOST))\n \t\t\tgoto bail_nuke_ah;\n-\t\tif (lws_add_http_header_status(wsi, 301, \u0026p, end))\n-\t\t\tgoto bail_nuke_ah;\n+\n \t\tn \u003d sprintf((char *)end, \u0022https://%s/\u0022,\n \t\t\t lws_hdr_simple_ptr(wsi, WSI_TOKEN_HOST));\n-\t\tif (lws_add_http_header_by_token(wsi, WSI_TOKEN_HTTP_LOCATION,\n-\t\t\t\tend, n, \u0026p, end))\n-\t\t\tgoto bail_nuke_ah;\n-\t\tif (lws_finalize_http_header(wsi, \u0026p, end))\n-\t\t\tgoto bail_nuke_ah;\n-\t\tn \u003d lws_write(wsi, start, p - start, LWS_WRITE_HTTP_HEADERS);\n+\n+\t\tn \u003d lws_http_redirect(wsi, end, n, \u0026p, end);\n \t\tif ((int)n \u003c 0)\n \t\t\tgoto bail_nuke_ah;\n \n \t\treturn lws_http_transaction_completed(wsi);\n \t}\n #endif\n-#endif\n \n #ifdef LWS_WITH_ACCESS_LOG\n \t/*\n@@ -563,14 +556,10 @@ lws_http_action(struct lws *wsi)\n \t\t\t\t\u0022http://\u0022, \u0022https://\u0022\n \t\t\t};\n \n-\t\t\t lwsl_err(\u0022Doing 301 '%s' org %s\u005cn\u0022, s, hit-\u003eorigin);\n+\t\t\tlwsl_notice(\u0022Doing 301 '%s' org %s\u005cn\u0022, s, hit-\u003eorigin);\n \n \t\t\tif (!lws_hdr_total_length(wsi, WSI_TOKEN_HOST))\n \t\t\t\tgoto bail_nuke_ah;\n-\t\t\tif (lws_add_http_header_status(wsi, 301, \u0026p, end))\n-\t\t\t\tgoto bail_nuke_ah;\n-\n-\t\t\tlwsl_debug(\u0022**** %s\u0022, hit-\u003eorigin);\n \n \t\t\t/* \u003e at start indicates deal with by redirect */\n \t\t\tif (hit-\u003eorigin_protocol \u0026 4)\n@@ -582,14 +571,8 @@ lws_http_action(struct lws *wsi)\n \t\t\t\t \u0022https://%s/%s/\u0022,\n \t\t\t\t lws_hdr_simple_ptr(wsi, WSI_TOKEN_HOST),\n \t\t\t\t uri_ptr);\n-\t\t\tif (lws_add_http_header_by_token(wsi,\n-\t\t\t\t\tWSI_TOKEN_HTTP_LOCATION,\n-\t\t\t\t\tend, n, \u0026p, end))\n-\t\t\t\tgoto bail_nuke_ah;\n-\t\t\tif (lws_finalize_http_header(wsi, \u0026p, end))\n-\t\t\t\tgoto bail_nuke_ah;\n-\t\t\tn \u003d lws_write(wsi, start, p - start,\n-\t\t\t\t\tLWS_WRITE_HTTP_HEADERS);\n+\n+\t\t\tn \u003d lws_http_redirect(wsi, end, n, \u0026p, end);\n \t\t\tif ((int)n \u003c 0)\n \t\t\t\tgoto bail_nuke_ah;\n \n","s":{"c":1756677296,"u": 3112}} ],"g": 4784,"chitpc": 0,"ehitpc": 0,"indexed":0 , "ab": 0, "si": 0, "db":0, "di":0, "sat":0, "lfc": "0000"}