Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add a set cookie interface in the response object #854

Closed
sansyrox opened this issue Jun 15, 2024 · 8 comments · Fixed by #870
Closed

add a set cookie interface in the response object #854

sansyrox opened this issue Jun 15, 2024 · 8 comments · Fixed by #870
Labels
enhancement New feature or request

Comments

@sansyrox
Copy link
Member

Something like this

@app.get("/cookie/")
def create_cookie():
    response = Response(....)
    response.set_cookie(key="fakesession", value="fake-cookie-session-value")
    return response
@sansyrox
Copy link
Member Author

@VishnuSanal , would you like to take this up in the coming week?

@xiaojin20
Copy link

可以是这样的:
@app.get("/cookie/")
def create_cookie():
response = Response(....)
response.set_custom_header("cookie", "cookievalue")
#....set_custom_header("server_id","1")
#....set_custom_header("server_id","2")
#可以是通用的,用户自定义添加,设定。
#return response //自动返回,或者自动添加到response中,无需显示返回。
return serve_html("./customheader.html")

@xiaojin20
Copy link

request.get_custom_header("server_id","2")

@sansyrox
Copy link
Member Author

@xiaojin20 , if it is just header , you should be able to do

response.headers["server_id"]=2

I can double check again :D

@xiaojin20
Copy link

xiaojin20 commented Jun 15, 2024 via email

@xiaojin20
Copy link

@xiaojin20 , if it is just header , you should be able to do

response.headers["server_id"]=2

I can double check again :D

有完整简单,示例代码????

@xiaojin20
Copy link

@app.get("/response")
def gigiiggj(response:Response):
response.headers["server_id"]="2"
#headers ={}
#up="files"
#return Response(description=up, headers=headers, status_code=200)
return response #<builtins.Request object at 0x7a5d867e10> ?????发送失败!还是?
#获取自定义response server_1
@app.get('/')
def index(request):
r=request.headers.get("server_id")#error 无法获取
print(r)
return "ok"

@sansyrox
Copy link
Member Author

有完整简单,示例代码????

Let me add some documentation and share it with you 😄

VishnuSanal added a commit to VishnuSanal/Robyn that referenced this issue Jun 24, 2024
VishnuSanal added a commit to VishnuSanal/Robyn that referenced this issue Jun 24, 2024
VishnuSanal added a commit to VishnuSanal/Robyn that referenced this issue Jun 24, 2024
VishnuSanal added a commit to VishnuSanal/Robyn that referenced this issue Jun 24, 2024
VishnuSanal added a commit to VishnuSanal/Robyn that referenced this issue Jun 25, 2024
VishnuSanal added a commit to VishnuSanal/Robyn that referenced this issue Jun 26, 2024
VishnuSanal added a commit to VishnuSanal/Robyn that referenced this issue Jun 26, 2024
VishnuSanal added a commit to VishnuSanal/Robyn that referenced this issue Jun 26, 2024
VishnuSanal added a commit to VishnuSanal/Robyn that referenced this issue Jun 26, 2024
VishnuSanal added a commit to VishnuSanal/Robyn that referenced this issue Jun 26, 2024
VishnuSanal added a commit to VishnuSanal/Robyn that referenced this issue Jun 26, 2024
sansyrox added a commit that referenced this issue Jul 3, 2024
* [#854] feat: implement `set_cookie` function

* [#854] fix(ci): fix clippy lint warning

* [#854] test: add integration test

* [#854] test: update test

* [#854] review: update code to use `try_borrow_mut`

* [#854] ci: remove unused import

* [#796] docs: update `robyn.pyi`

* [#796] docs: update docs with `set_cookies` function

* docs: add docstring and types

* Apply suggestions from code review

---------

Co-authored-by: Sanskar Jethi <29942790+sansyrox@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants