nodemcu 里 lua 的 http web server 怎么同步获取多个 http 请求 header 的内容?

2022-04-07 09:44:08 +08:00
 zjsxwc
我用了这个 lua 代码

https://github.com/nodemcu/nodemcu-firmware/blob/release/lua_modules/http/httpserver.lua

把 nodemcu 作为一个简单的 http server 。

但这个代码的使用方式如图:
https://gitee.com/zjsxwc/image-bed/raw/master/v2ex/2022-04-07_09-31.png

是和 js 回调一样的异步获取 http 请求 header 内容的,
如果我想尝试获取多个 header (比如 cookie 和 useragent )后再处理后面业务,应该怎么写,
而且得考虑请求可能根本没有带上 cookie 或 useragent 的情况,

我找了 lua 类似 js 的 promise 库( https://github.com/brianhang/deferred-lua ),
好像也没有处理`当请求可能根本没有带上 cookie 或 useragent 时`的情况。

实在不行,我就只能修改 httpserver.lua ,搞个局部 table 变量收集所有 header ,在这个 182 行回调时把这个 table 变量也传过去了,
https://github.com/nodemcu/nodemcu-firmware/blob/release/lua_modules/http/httpserver.lua#L182
569 次点击
所在节点    程序员
0 条回复

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/845399

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX