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 extension to set/delete cookies #20

Merged
merged 1 commit into from
Jul 29, 2019
Merged

Add extension to set/delete cookies #20

merged 1 commit into from
Jul 29, 2019

Conversation

waiting-for-dev
Copy link
Owner

This extension helps with the addition of the Set-Cookie header
to the response, which is the way the server has to instruct the
browser to keep a cookie. A cookie can be added with the
#add_cookie method, while it can be marked for deletion with
#delete_cookie. Remember that marking a cookie for deletion just
means adding the same cookie name with an expiration time in the
past.

require 'web_pipe'

WebPipe.load_extensions(:cookies)

class SetCookie
  include WebPipe

  plug :set_cookie, ->(conn) { conn.set_cookie('foo', 'bar', path: '/') }
end

class DeleteCookie
  include WebPipe

  plug :delete_cookie, ->(conn) { conn.delete_cookie('foo', path: '/') }
end

This extension helps with the addition of the `Set-Cookie` header
to the response, which is the way the server has to instruct the
browser to keep a cookie. A cookie can be added with the
`#add_cookie` method, while it can be marked for deletion with
`#delete_cookie`. Remember that marking a cookie for deletion just
means adding the same cookie name with an expiration time in the
past.

```ruby
require 'web_pipe'

WebPipe.load_extensions(:cookies)

class SetCookie
  include WebPipe

  plug :set_cookie, ->(conn) { conn.set_cookie('foo', 'bar', path: '/') }
end

class DeleteCookie
  include WebPipe

  plug :delete_cookie, ->(conn) { conn.delete_cookie('foo', path: '/') }
end
```
@waiting-for-dev waiting-for-dev added the enhancement New feature or request label Jul 29, 2019
@waiting-for-dev waiting-for-dev merged commit ba0f78e into master Jul 29, 2019
@waiting-for-dev waiting-for-dev deleted the cookies branch July 29, 2019 10:15
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 this pull request may close these issues.

1 participant