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 multiple cookies example & test #135

Merged
merged 1 commit into from
May 17, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ defp process_status_code(status_code), do: status_code

HTTPoison now comes with async requests!

```iex
```elixir
iex> HTTPoison.get! "https://github.com/", %{}, stream_to: self
%HTTPoison.AsyncResponse{id: #Reference<0.0.0.1654>}
iex> flush
Expand All @@ -141,6 +141,17 @@ iex> flush
:ok
```

### Cookies

HTTPoison allows you to send cookies:

```iex
iex> HTTPoison.get!("http://httparrot.herokuapp.com/cookies", %{}, hackney: [cookie: ["session=a933ec1dd923b874e691; logged_in=true"]])
%HTTPoison.Response{body: "{\n \"cookies\": {\n \"session\": \"a933ec1dd923b874e691\",\n \"logged_in\": \"true\"\n }\n}",
headers: [{"Connection", "keep-alive"}, ...],
status_code: 200}
```

You can see more usage examples in the test files (located in the
[`test/`](test)) directory.

Expand Down
4 changes: 2 additions & 2 deletions test/httpoison_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,8 @@ defmodule HTTPoisonTest do
end

test "send cookies" do
response = HTTPoison.get!("localhost:8080/cookies", %{}, hackney: [cookie: [{"SESSION", "123"}]])
assert response.body =~ ~r(\"SESSION\".*\"123\")
response = HTTPoison.get!("localhost:8080/cookies", %{}, hackney: [cookie: ["foo=1; bar=2"]])
assert response.body |> String.replace( ~r/\s|\r?\n/, "") |> String.replace(~r/\"/, "'") |> JSX.decode! == %{"cookies" => %{"foo" => "1", "bar" => "2"}}
end

test "exception" do
Expand Down