Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/princemaple/cookie_jar
CookieJar stores your cookies and applies them to future requests
https://github.com/princemaple/cookie_jar
cookie elixir http
Last synced: 4 days ago
JSON representation
CookieJar stores your cookies and applies them to future requests
- Host: GitHub
- URL: https://github.com/princemaple/cookie_jar
- Owner: princemaple
- License: mit
- Created: 2017-02-09T23:22:51.000Z (almost 8 years ago)
- Default Branch: main
- Last Pushed: 2024-12-25T22:44:07.000Z (10 days ago)
- Last Synced: 2024-12-30T10:11:25.716Z (6 days ago)
- Topics: cookie, elixir, http
- Language: Elixir
- Homepage: https://hexdocs.pm/cookie_jar
- Size: 129 KB
- Stars: 14
- Watchers: 3
- Forks: 9
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# CookieJar
[![hex.pm version](https://img.shields.io/hexpm/v/cookie_jar.svg?style=flat)](https://hex.pm/packages/cookie_jar)
[![API Docs](https://img.shields.io/badge/api-docs-blue.svg?style=flat)](https://hexdocs.pm/cookie_jar/)![COOKIE JAR](https://cloud.githubusercontent.com/assets/1329716/22807691/5fe454d6-ef7c-11e6-8e0b-30aca685c83a.jpg)
## Installation
The package can be installed
by adding `cookie_jar` to your list of dependencies in `mix.exs`:```elixir
def deps do
[{:cookie_jar, "~> 1.0"}]
end
```## Usage
1. Add alias (optional)
```elixir
alias CookieJar.HTTPoison, as: HTTPoison
```2. Get a cookie jar
```elixir
{:ok, jar} = CookieJar.new
```Alternatively, you can use a permenent cookie jar by starting one as part of your supervision tree:
```elixir
def start(_type, _args) do
children = [
{CookieJar.Server, name: MyApp.CookieJar},
...
```Then you can use `MyApp.CookieJar` as the application-wide jar.
3. Shove the jar into all http calls
```diff
- HTTPoison.get("https://example.com/api/call")
+ HTTPoison.get(jar, "https://example.com/api/call")
```4. Profit (cookies imprisoned)
All cookies from "Set-Cookie:" response headers are now stored in the jar and will be automatically sent back through "Cookie:" request headers. CookieJar respect the following attributes in the cookies:- Domain: To limit abuses, CookieJar only allows `Domain` to be set to the current hostname of the request or its immediate parent domain.
- Path: A cookie can limit the sending back to part of the path tree in the request
- Secure: A secure cookie can only be set by https responses and used by https requests
- Max-Age: A cookie can specify its max ageAll other attributes are silently ignored.
**Take a look at [the docs](https://hexdocs.pm/cookie_jar)**
- [How to directly use CookieJar](https://hexdocs.pm/cookie_jar/CookieJar.html#content)
- [HTTPoison adapter](https://hexdocs.pm/cookie_jar/CookieJar.HTTPoison.html#content)
- [HTTPotion adapter](https://hexdocs.pm/cookie_jar/CookieJar.HTTPotion.html#content)