Comments (11)
same question about #35
from lor.
如果使用的是require "lor.resty.cookie"
,那么引入的就是lua-resty-cookie这个包,使用方法请参看它的github文档。
建议先不要使用OpenResty-China来测,先单独使用lua-resty-cookie这个包把你需要的场景测试一遍,掌握它的用法后就可以随意移植了。
from lor.
我测试的时候写过一个小例子供你参考:
app:get("/cookie", function(req, res, next)
local test_cookie = req.cookie.get("test_cookie")
if not test_cookie then
req.cookie.set("test_cookie", "12345")
res:send("cookie test, empty cookie[test_cookie]")
else
res:send("cookie test, exist cookie[test_cookie]: " .. test_cookie)
end
end)
第一次访问http://localhost:8888/cookie 时cookie为空,第二次访问时就可以看到已经设置的值了,说明设置成功
from lor.
@sumory 你这个小例子还是报错的,我这边其实用OpenResty-China这个已经改完了,只是要加一个Cookie识别,我原来是在django上开发,功能全部做出来了,只是它的性能不行,所以才想改到openresty上试试.
curl -v http://127.0.0.1:8888/iot/v1.0/app/auth/abc/123456/
* Hostname was NOT found in DNS cache
* Trying 127.0.0.1...
* Connected to 127.0.0.1 (127.0.0.1) port 8888 (#0)
> GET /iot/v1.0/app/auth/abc/123456/ HTTP/1.1
> User-Agent: curl/7.38.0
> Host: 127.0.0.1:8888
> Accept: */*
>
< HTTP/1.1 200 OK
* Server openresty/1.11.2.1 is not blacklisted
< Server: openresty/1.11.2.1
< Date: Mon, 09 Jan 2017 09:50:26 GMT
< Content-Type: text/plain; charset=utf8
< Transfer-Encoding: chunked
< Connection: keep-alive
< Set-Cookie: session=ZGg3cbYCkgtmt6nMLfb7SA..|1483959026|2ssKGc2jV5xVQaLSCkt4_Q..|qOeWVsBM_1tLQwu4aWNTGphuLNU.; Expires=Mon, 09 Jan 2017 10:50:26 GMT; Max-Age=3600; Path=/; SameSite=Lax; HttpOnly
< X-Powered-By: Lor Framework
<
get data nil
debug print table: 0x414901e0
key: host value: string
key: accept value: string
key: user-agent value: string
{"srvs":"127.0.0.10:1883","uuid":"f1852fcde4294f8c917522a12ec25fd1","time":"1483955426","sign":"1B909F6175F3A7785FE44BDA599CD66E21D4B932","expire":600,"ok":true}
{"msg":"用户不存在","ok":false,"err":"UserNotExists"}
* Connection #0 to host 127.0.0.1 left intact
from lor.
@sumory 对于这个cookie的设置与django区别很大,所以很不明白 lor cookie 的这个功能如何去写,下面是django返回的cookie
curl -v http://127.0.0.1:8000/iot/v1.0/app/auth/abc/123456/
* Hostname was NOT found in DNS cache
* Trying 127.0.0.1...
* Connected to 127.0.0.1 (127.0.0.1) port 8000 (#0)
> GET /iot/v1.0/app/auth/abc/123456/ HTTP/1.1
> User-Agent: curl/7.38.0
> Host: 127.0.0.1:8000
> Accept: */*
>
* HTTP 1.0, assume close after body
< HTTP/1.0 200 OK
< Date: Mon, 09 Jan 2017 09:56:20 GMT
< Server: WSGIServer/0.1 Python/2.7.10
< Vary: Cookie
< X-Frame-Options: SAMEORIGIN
< Content-Type: application/json; charset=utf-8
< Set-Cookie: sessionid=239hbmw00r0aft9vjqqawfdc7a9xyick; expires=Mon, 09-Jan-2017 10:06:20 GMT; httponly; Max-Age=600; Path=/
<
* Closing connection 0
{"ok": true, "uuid": "f1852fcde4294f8c917522a12ec25fd1", "sign": "239hbmw00r0aft9vjqqawfdc7a9xyick", "srvs": "127.0.0.1:1883", "expire": 600, "time": "1483955780"}yjdwbj@mint17:~/workspace/openresty-china$
from lor.
刚才的例子在lor0.2.6下测试通过,我不清楚你的具体场景上下文,也没有使用过django,你贴出的文本我也看不懂要表达啥意思。我觉得不应该用一种语言一种框架的思维去限定其他语言和框架的使用习惯。anyway! 问题解决了就好。
from lor.
@sumory 你这个通过是说,你赋值的cookie 是在HTTP返回的文本里面吧.不是HTTP的头部"Cookie"字段吧.
我一直是想要是设置到response的 HTTP头部里面,不是返回的HTTP的文本里面.
Cookie: sessionid=oapb08l2tdielg6c3wgam9tk6tyxryiy; expires=Mon, 09-Jan-2017 11:12:03 GMT; httponly; Max-Age=600; Path=/
from lor.
文本是我额外打出来给你看的,设置的cookie是在header里啊。
from lor.
@sumory 这里就有两个Set-Cookie了,能否用下面这个替换上面那一个?谢谢.
from lor.
为啥要替换?客户端 cookie这样是能写进去的,下次请求这个字段就进入新的请求头了。
你如果非得想替换就去研究lua-resty-cookie,实在实现不了你的想法,那重写个也行,没多少代码。
from lor.
@sumory 我看了一下源码,直接res:set_header('Set-Cookie',"blablalba") , 其实是调用ngx.header['Set-Cookie'] = 'blablaba", 谢谢.
from lor.
Related Issues (20)
- 模板引擎能支持一下vue的渲染吗? HOT 2
- session插件问题
- lor error message: may lead to race conditions between concurrent requests HOT 2
- Documentation in English
- 现在还有在维护吗? HOT 2
- demo 无法启动 HOT 1
- 运行lord生成的项目网页直接返回模板文件名 HOT 1
- Windows环境下如何使用呢 HOT 1
- 如何通过systemd 启动lor web站呢? HOT 1
- 使用lor, 没有数据验证和封装好的数据库curd吗?
- trie.lua第75行有bug HOT 4
- post大数据丢失问题 HOT 4
- 有哪些公司生产环境项目在用lor呢? HOT 2
- update lor on opm to 0.3.4 and add lord HOT 1
- request body 太大了,不建议 lor 去直接读文件,or 读文件的操作都是阻塞的,建议根据你的需求调大 `client_body_buffer_size ` 的大小 HOT 2
- 执行命令报错 HOT 6
- node.lua 第26行有警告
- cygwin环境安装sumory/lor成功后报thread.exdata找不到 HOT 2
- 不支持 curl -I HOT 2
- 019/12/28 11:39:36 [error] 18659#18659: *1580 [lua] session.lua:85: func(): cannot get session_data:no cookie found in the current request HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from lor.