{"schema":"libjg2-1",
"vpath":"/git/",
"avatar":"/git/avatar/",
"alang":"",
"gen_ut":1752719382,
"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":"23cda3f4b1fd744a9d3f726a80fa5ed4",
"commit": {"type":"commit",
"time": 1595847230,
"time_ofs": 60,
"oid_tree": { "oid": "f2846c03c929ce77b80e645c44910fd125978895", "alias": []},
"oid":{ "oid": "beacbbb38c5ee56b7e95b427bf575952c3d1fd94", "alias": []},
"msg": "minimal-examples: http-server-dyn: Check if the first part of received url is our mountpoint",
"sig_commit": { "git_time": { "time": 1595847230, "offset": 60 }, "name": "Andy Green", "email": "andy@warmcat.com", "md5": "c50933ca2aa61e0fe2c43d46bb6b59cb" },
"sig_author": { "git_time": { "time": 1595828363, "offset": -300 }, "name": "Soumendra Ganguly", "email": "soumendraganguly@gmail.com", "md5": "102e42d31d215738e6a63244b8233e56" }},
"body": "minimal-examples: http-server-dyn: Check if the first part of received url is our mountpoint\n\nIn the case of the http-server-dyn example, there is only one protocol.\nThe mounts will override the area of the url space they are set up for,\nand the \u0022gaps\u0022 will fall back to the default protocol, which in turn\ndefaults to protocol[0] at the moment. So you always get the dyn\nprotocol action on unknown parts of the URL space.\n\nThis solves that behaviour by adding a new protocols[0] that calls\nstraight through to the default protocol handler lws_callback_http_dummy(),\nand moves the dyn handler to be protocols[1].\n\nIn addition it shows how to check the url path in the dyn handler for\ncases where user code doesn't want to add the second protocol."
,
"diff": "diff --git a/minimal-examples/http-server/minimal-http-server-dynamic/minimal-http-server-dynamic.c b/minimal-examples/http-server/minimal-http-server-dynamic/minimal-http-server-dynamic.c\nindex 77ca694..af0b220 100644\n--- a/minimal-examples/http-server/minimal-http-server-dynamic/minimal-http-server-dynamic.c\n+++ b/minimal-examples/http-server/minimal-http-server-dynamic/minimal-http-server-dynamic.c\n@@ -49,11 +49,27 @@ callback_dynamic_http(struct lws *wsi, enum lws_callback_reasons reason,\n \tswitch (reason) {\n \tcase LWS_CALLBACK_HTTP:\n \n-\t\t/* in contains the url part after our mountpoint /dyn, if any */\n-\t\tlws_snprintf(pss-\u003epath, sizeof(pss-\u003epath), \u0022%s\u0022, (const char *)in);\n+\t\t/*\n+\t\t * If you want to know the full url path used, you can get it\n+\t\t * like this\n+\t\t *\n+\t\t * n \u003d lws_hdr_copy(wsi, buf, sizeof(buf), WSI_TOKEN_GET_URI);\n+\t\t *\n+\t\t * The base path is the first (n - strlen((const char *)in))\n+\t\t * chars in buf.\n+\t\t */\n+\n+\t\t/*\n+\t\t * In contains the url part after the place the mount was\n+\t\t * positioned at, eg, if positioned at \u0022/dyn\u0022 and given\n+\t\t * \u0022/dyn/mypath\u0022, in will contain /mypath\n+\t\t */\n+\t\tlws_snprintf(pss-\u003epath, sizeof(pss-\u003epath), \u0022%s\u0022,\n+\t\t\t\t(const char *)in);\n \n \t\tlws_get_peer_simple(wsi, (char *)buf, sizeof(buf));\n-\t\tlwsl_notice(\u0022%s: HTTP: connection %s\u005cn\u0022, __func__, (const char *)buf);\n+\t\tlwsl_notice(\u0022%s: HTTP: connection %s, path %s\u005cn\u0022, __func__,\n+\t\t\t\t(const char *)buf, pss-\u003epath);\n \n \t\t/*\n \t\t * prepare and write http headers... with regards to content-\n@@ -178,10 +194,11 @@ callback_dynamic_http(struct lws *wsi, enum lws_callback_reasons reason,\n \treturn lws_callback_http_dummy(wsi, reason, user, in, len);\n }\n \n-static const struct lws_protocols protocol \u003d\n+static const struct lws_protocols defprot \u003d\n+\t{ \u0022defprot\u0022, lws_callback_http_dummy, 0, 0 }, protocol \u003d\n \t{ \u0022http\u0022, callback_dynamic_http, sizeof(struct pss), 0 };\n \n-static const struct lws_protocols *pprotocols[] \u003d { \u0026protocol, NULL };\n+static const struct lws_protocols *pprotocols[] \u003d { \u0026defprot, \u0026protocol, NULL };\n \n /* override the default mount for /dyn in the URL space */\n \n","s":{"c":1752719382,"u": 1767}}
],"g": 2555,"chitpc": 0,"ehitpc": 0,"indexed":0
,
"ab": 0, "si": 0, "db":0, "di":0, "sat":0, "lfc": "0000"}