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

Adds "ctx.cookie()" response transformer #103

Merged
merged 1 commit into from Apr 18, 2020
Merged

Adds "ctx.cookie()" response transformer #103

merged 1 commit into from Apr 18, 2020

Conversation

kettanaito
Copy link
Member

@kettanaito kettanaito commented Apr 18, 2020

Changes

  • Adds new ctx.cookie() utility
ctx.cookie('name', 'value', {
  httpOnly: false,
  expires: 'date string',
  domain: 'string'
})

Additionally, any options from cookie.

GitHub

Implementation

As setting Set-Cookie header on Response is generally forbidden, and Cookie Store is not ready, this feature takes advantage of response composition chain being executed on the client's side, and sets given cookies on the document.cookie directly. Such behavior imitates as if cookies received from response were set on the client side.

Calling ctx.cookie() also sets the Set-Cookie header on the client-side response object, so you can:

  1. Inspect and interact with res.headers.get('set-cookie') inside response resolvers.
  2. Inspect the cookie presence in the logs.

@kettanaito kettanaito merged commit ca18b75 into master Apr 18, 2020
@kettanaito kettanaito deleted the 101-cookies branch April 18, 2020 09:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support mocking of cookies
1 participant