Code Monkey home page Code Monkey logo

Comments (11)

sumory avatar sumory commented on August 17, 2024

same question about #35

from lor.

sumory avatar sumory commented on August 17, 2024

如果使用的是require "lor.resty.cookie",那么引入的就是lua-resty-cookie这个包,使用方法请参看它的github文档。

建议先不要使用OpenResty-China来测,先单独使用lua-resty-cookie这个包把你需要的场景测试一遍,掌握它的用法后就可以随意移植了。

from lor.

sumory avatar sumory commented on August 17, 2024

我测试的时候写过一个小例子供你参考:

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.

yjdwbj avatar yjdwbj commented on August 17, 2024

@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.

yjdwbj avatar yjdwbj commented on August 17, 2024

@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.

sumory avatar sumory commented on August 17, 2024

刚才的例子在lor0.2.6下测试通过,我不清楚你的具体场景上下文,也没有使用过django,你贴出的文本我也看不懂要表达啥意思。我觉得不应该用一种语言一种框架的思维去限定其他语言和框架的使用习惯。anyway! 问题解决了就好。

from lor.

yjdwbj avatar yjdwbj commented on August 17, 2024

@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.

sumory avatar sumory commented on August 17, 2024

image

文本是我额外打出来给你看的,设置的cookie是在header里啊。

from lor.

yjdwbj avatar yjdwbj commented on August 17, 2024

@sumory 这里就有两个Set-Cookie了,能否用下面这个替换上面那一个?谢谢.

from lor.

sumory avatar sumory commented on August 17, 2024

为啥要替换?客户端 cookie这样是能写进去的,下次请求这个字段就进入新的请求头了。
你如果非得想替换就去研究lua-resty-cookie,实在实现不了你的想法,那重写个也行,没多少代码。

from lor.

yjdwbj avatar yjdwbj commented on August 17, 2024

@sumory 我看了一下源码,直接res:set_header('Set-Cookie',"blablalba") , 其实是调用ngx.header['Set-Cookie'] = 'blablaba", 谢谢.

from lor.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.