@@ -5,13 +5,13 @@ defmodule HTTPoisonTest do
55 alias HTTPoison.Request
66
77 test "get" do
8- assert_response ( HTTPoison . get ( "localhost:8080 /deny" ) , fn response ->
8+ assert_response ( HTTPoison . get ( "localhost:4002 /deny" ) , fn response ->
99 assert :erlang . size ( response . body ) == 197
1010 end )
1111 end
1212
1313 test "get with params" do
14- resp = HTTPoison . get ( "localhost:8080 /get" , [ ] , params: % { foo: "bar" , baz: "bong" } )
14+ resp = HTTPoison . get ( "localhost:4002 /get" , [ ] , params: % { foo: "bar" , baz: "bong" } )
1515
1616 assert_response ( resp , fn response ->
1717 args = Jason . decode! ( response . body ) [ "args" ]
@@ -20,14 +20,14 @@ defmodule HTTPoisonTest do
2020 assert args |> Map . keys ( ) |> length == 2
2121
2222 assert Request . to_curl ( response . request ) ==
23- { :ok , "curl -X GET http://localhost:8080 /get?baz=bong&foo=bar" }
23+ { :ok , "curl -X GET http://localhost:4002 /get?baz=bong&foo=bar" }
2424 end )
2525 end
2626
2727 test "get with params in url and options" do
2828 resp =
2929 HTTPoison . get (
30- "localhost:8080 /get?bar=zing&foo=first" ,
30+ "localhost:4002 /get?bar=zing&foo=first" ,
3131 [ ] ,
3232 params: [ { "foo" , "second" } , { "baz" , "bong" } ]
3333 )
@@ -41,106 +41,106 @@ defmodule HTTPoisonTest do
4141
4242 assert Request . to_curl ( response . request ) ==
4343 { :ok ,
44- "curl -X GET http://localhost:8080 /get?bar=zing&foo=first&foo=second&baz=bong" }
44+ "curl -X GET http://localhost:4002 /get?bar=zing&foo=first&foo=second&baz=bong" }
4545 end )
4646 end
4747
4848 test "head" do
49- assert_response ( HTTPoison . head ( "localhost:8080 /get" ) , fn response ->
49+ assert_response ( HTTPoison . head ( "localhost:4002 /get" ) , fn response ->
5050 assert response . body == ""
51- assert Request . to_curl ( response . request ) == { :ok , "curl -X HEAD http://localhost:8080 /get" }
51+ assert Request . to_curl ( response . request ) == { :ok , "curl -X HEAD http://localhost:4002 /get" }
5252 end )
5353 end
5454
5555 test "post charlist body" do
56- assert_response ( HTTPoison . post ( "localhost:8080 /post" , 'test' ) , fn response ->
57- assert Request . to_curl ( response . request ) == { :ok , "curl -X POST http://localhost:8080 /post" }
56+ assert_response ( HTTPoison . post ( "localhost:4002 /post" , 'test' ) , fn response ->
57+ assert Request . to_curl ( response . request ) == { :ok , "curl -X POST http://localhost:4002 /post" }
5858 end )
5959 end
6060
6161 test "post binary body" do
6262 { :ok , file } = File . read ( fixture_path ( "image.png" ) )
6363
64- assert_response ( HTTPoison . post ( "localhost:8080 /post" , file ) , fn response ->
64+ assert_response ( HTTPoison . post ( "localhost:4002 /post" , file ) , fn response ->
6565 assert Request . to_curl ( response . request ) ==
66- { :ok , "curl -X POST -d '#{ file } ' http://localhost:8080 /post" }
66+ { :ok , "curl -X POST -d '#{ file } ' http://localhost:4002 /post" }
6767 end )
6868 end
6969
7070 test "post form data" do
7171 assert_response (
72- HTTPoison . post ( "localhost:8080 /post" , { :form , [ key: "value" ] } , % {
72+ HTTPoison . post ( "localhost:4002 /post" , { :form , [ key: "value" ] } , % {
7373 "Content-type" => "application/x-www-form-urlencoded"
7474 } ) ,
7575 fn response ->
7676 Regex . match? ( ~r/ "key".*"value"/ , response . body )
7777
7878 assert Request . to_curl ( response . request ) ==
7979 { :ok ,
80- "curl -X POST -H 'Content-type: application/x-www-form-urlencoded' -F 'key=value' http://localhost:8080 /post" }
80+ "curl -X POST -H 'Content-type: application/x-www-form-urlencoded' -F 'key=value' http://localhost:4002 /post" }
8181 end
8282 )
8383 end
8484
8585 test "put" do
86- assert_response ( HTTPoison . put ( "localhost:8080 /put" , "test" ) , fn response ->
86+ assert_response ( HTTPoison . put ( "localhost:4002 /put" , "test" ) , fn response ->
8787 assert Request . to_curl ( response . request ) ==
88- { :ok , "curl -X PUT -d 'test' http://localhost:8080 /put" }
88+ { :ok , "curl -X PUT -d 'test' http://localhost:4002 /put" }
8989 end )
9090 end
9191
9292 test "put without body" do
93- assert_response ( HTTPoison . put ( "localhost:8080 /put" ) , fn response ->
93+ assert_response ( HTTPoison . put ( "localhost:4002 /put" ) , fn response ->
9494 assert Request . to_curl ( response . request ) ==
95- { :ok , "curl -X PUT http://localhost:8080 /put" }
95+ { :ok , "curl -X PUT http://localhost:4002 /put" }
9696 end )
9797 end
9898
9999 test "patch" do
100- assert_response ( HTTPoison . patch ( "localhost:8080 /patch" , "test" ) , fn response ->
100+ assert_response ( HTTPoison . patch ( "localhost:4002 /patch" , "test" ) , fn response ->
101101 assert Request . to_curl ( response . request ) ==
102- { :ok , "curl -X PATCH -d 'test' http://localhost:8080 /patch" }
102+ { :ok , "curl -X PATCH -d 'test' http://localhost:4002 /patch" }
103103 end )
104104 end
105105
106106 test "delete" do
107- assert_response ( HTTPoison . delete ( "localhost:8080 /delete" ) , fn response ->
107+ assert_response ( HTTPoison . delete ( "localhost:4002 /delete" ) , fn response ->
108108 assert Request . to_curl ( response . request ) ==
109- { :ok , "curl -X DELETE http://localhost:8080 /delete" }
109+ { :ok , "curl -X DELETE http://localhost:4002 /delete" }
110110 end )
111111 end
112112
113113 test "options" do
114- assert_response ( HTTPoison . options ( "localhost:8080 /get" ) , fn response ->
114+ assert_response ( HTTPoison . options ( "localhost:4002 /get" ) , fn response ->
115115 assert get_header ( response . headers , "content-length" ) == "0"
116116 assert is_binary ( get_header ( response . headers , "allow" ) )
117117
118118 assert Request . to_curl ( response . request ) ==
119- { :ok , "curl -X OPTIONS http://localhost:8080 /get" }
119+ { :ok , "curl -X OPTIONS http://localhost:4002 /get" }
120120 end )
121121 end
122122
123123 test "option follow redirect absolute url" do
124124 assert_response (
125125 HTTPoison . get (
126- "http://localhost:8080 /redirect-to?url=http%3A%2F%2Flocalhost:8080 %2Fget" ,
126+ "http://localhost:4002 /redirect-to?url=http%3A%2F%2Flocalhost:4002 %2Fget" ,
127127 [ ] ,
128128 follow_redirect: true
129129 ) ,
130130 fn response ->
131131 assert Request . to_curl ( response . request ) ==
132132 { :ok ,
133- "curl -L --max-redirs 5 -X GET http://localhost:8080 /redirect-to?url=http%3A%2F%2Flocalhost:8080 %2Fget" }
133+ "curl -L --max-redirs 5 -X GET http://localhost:4002 /redirect-to?url=http%3A%2F%2Flocalhost:4002 %2Fget" }
134134 end
135135 )
136136 end
137137
138138 test "option follow redirect relative url" do
139139 assert_response (
140- HTTPoison . get ( "http://localhost:8080 /relative-redirect/1" , [ ] , follow_redirect: true ) ,
140+ HTTPoison . get ( "http://localhost:4002 /relative-redirect/1" , [ ] , follow_redirect: true ) ,
141141 fn response ->
142142 assert Request . to_curl ( response . request ) ==
143- { :ok , "curl -L --max-redirs 5 -X GET http://localhost:8080 /relative-redirect/1" }
143+ { :ok , "curl -L --max-redirs 5 -X GET http://localhost:4002 /relative-redirect/1" }
144144 end
145145 )
146146 end
@@ -149,14 +149,14 @@ defmodule HTTPoisonTest do
149149 hackney = [ basic_auth: { "user" , "pass" } ]
150150
151151 assert_response (
152- HTTPoison . get ( "http://localhost:8080 /basic-auth/user/pass" , [ ] , hackney: hackney )
152+ HTTPoison . get ( "http://localhost:4002 /basic-auth/user/pass" , [ ] , hackney: hackney )
153153 )
154154 end
155155
156156 test "explicit http scheme" do
157- assert_response ( HTTPoison . head ( "http://localhost:8080 /get" ) , fn response ->
157+ assert_response ( HTTPoison . head ( "http://localhost:4002 /get" ) , fn response ->
158158 assert Request . to_curl ( response . request ) ==
159- { :ok , "curl -X HEAD http://localhost:8080 /get" }
159+ { :ok , "curl -X HEAD http://localhost:4002 /get" }
160160 end )
161161 end
162162
@@ -181,44 +181,44 @@ defmodule HTTPoisonTest do
181181 end
182182
183183 test "char list URL" do
184- assert_response ( HTTPoison . head ( 'localhost:8080 /get' ) , fn response ->
184+ assert_response ( HTTPoison . head ( 'localhost:4002 /get' ) , fn response ->
185185 assert Request . to_curl ( response . request ) ==
186- { :ok , "curl -X HEAD http://localhost:8080 /get" }
186+ { :ok , "curl -X HEAD http://localhost:4002 /get" }
187187 end )
188188 end
189189
190190 test "request headers as a map" do
191191 map_header = % { "X-Header" => "X-Value" }
192- assert response = HTTPoison . get! ( "localhost:8080 /get" , map_header )
192+ assert response = HTTPoison . get! ( "localhost:4002 /get" , map_header )
193193 assert response . body =~ "X-Value"
194194
195195 assert Request . to_curl ( response . request ) ==
196- { :ok , "curl -X GET -H 'X-Header: X-Value' http://localhost:8080 /get" }
196+ { :ok , "curl -X GET -H 'X-Header: X-Value' http://localhost:4002 /get" }
197197 end
198198
199199 test "cached request" do
200200 if_modified = % { "If-Modified-Since" => "Tue, 11 Dec 2012 10:10:24 GMT" }
201- response = HTTPoison . get! ( "localhost:8080 /cache" , if_modified )
201+ response = HTTPoison . get! ( "localhost:4002 /cache" , if_modified )
202202 assert % HTTPoison.Response { status_code: 304 , body: "" } = response
203203
204204 assert Request . to_curl ( response . request ) ==
205205 { :ok ,
206- "curl -X GET -H 'If-Modified-Since: Tue, 11 Dec 2012 10:10:24 GMT' http://localhost:8080 /cache" }
206+ "curl -X GET -H 'If-Modified-Since: Tue, 11 Dec 2012 10:10:24 GMT' http://localhost:4002 /cache" }
207207 end
208208
209209 test "send cookies" do
210- response = HTTPoison . get! ( "localhost:8080 /cookies" , % { } , hackney: [ cookie: [ "foo=1; bar=2" ] ] )
210+ response = HTTPoison . get! ( "localhost:4002 /cookies" , % { } , hackney: [ cookie: [ "foo=1; bar=2" ] ] )
211211 assert Jason . decode! ( response . body ) == % { "cookies" => % { "foo" => "1" , "bar" => "2" } }
212212 end
213213
214214 test "receive cookies" do
215- response = HTTPoison . get! ( "localhost:8080 /cookies/set?foo=1&bar=2" )
215+ response = HTTPoison . get! ( "localhost:4002 /cookies/set?foo=1&bar=2" )
216216 has_foo = Enum . member? ( response . headers , { "set-cookie" , "foo=1; Version=1; Path=/" } )
217217 has_bar = Enum . member? ( response . headers , { "set-cookie" , "bar=2; Version=1; Path=/" } )
218218 assert has_foo and has_bar
219219
220220 assert Request . to_curl ( response . request ) ==
221- { :ok , "curl -X GET http://localhost:8080 /cookies/set?foo=1&bar=2" }
221+ { :ok , "curl -X GET http://localhost:4002 /cookies/set?foo=1&bar=2" }
222222 end
223223
224224 test "exception" do
@@ -231,7 +231,7 @@ defmodule HTTPoisonTest do
231231
232232 test "asynchronous request" do
233233 { :ok , % HTTPoison.AsyncResponse { id: id } } =
234- HTTPoison . get ( "localhost:8080 /get" , [ ] , stream_to: self ( ) )
234+ HTTPoison . get ( "localhost:4002 /get" , [ ] , stream_to: self ( ) )
235235
236236 assert_receive % HTTPoison.AsyncStatus { id: ^ id , code: 200 } , 1_000
237237 assert_receive % HTTPoison.AsyncHeaders { id: ^ id , headers: headers } , 1_000
@@ -242,7 +242,7 @@ defmodule HTTPoisonTest do
242242
243243 test "asynchronous request with explicit streaming using [async: :once]" do
244244 { :ok , resp = % HTTPoison.AsyncResponse { id: id } } =
245- HTTPoison . get ( "localhost:8080 /get" , [ ] , stream_to: self ( ) , async: :once )
245+ HTTPoison . get ( "localhost:4002 /get" , [ ] , stream_to: self ( ) , async: :once )
246246
247247 assert_receive % HTTPoison.AsyncStatus { id: ^ id , code: 200 } , 100
248248
@@ -264,21 +264,21 @@ defmodule HTTPoisonTest do
264264 test "asynchronous redirected get request" do
265265 { :ok , % HTTPoison.AsyncResponse { id: id } } =
266266 HTTPoison . get (
267- "localhost:8080 /redirect/2" ,
267+ "localhost:4002 /redirect/2" ,
268268 [ ] ,
269269 stream_to: self ( ) ,
270270 hackney: [ follow_redirect: true ]
271271 )
272272
273273 assert_receive % HTTPoison.AsyncRedirect { id: ^ id , to: to , headers: headers } , 1_000
274- assert to == "http://localhost:8080 /redirect/1"
274+ assert to == "http://localhost:4002 /redirect/1"
275275 assert is_list ( headers )
276276 end
277277
278278 test "multipart upload" do
279279 response =
280280 HTTPoison . post (
281- "localhost:8080 /post" ,
281+ "localhost:4002 /post" ,
282282 { :multipart , [ { :file , "test/test_helper.exs" } , { "name" , "value" } ] }
283283 )
284284
@@ -289,14 +289,14 @@ defmodule HTTPoisonTest do
289289 expected = % { "some" => "bytes" }
290290 enumerable = Jason . encode! ( expected ) |> String . split ( "" )
291291 headers = % { "Content-type" => "application/json" }
292- response = HTTPoison . post ( "localhost:8080 /post" , { :stream , enumerable } , headers )
292+ response = HTTPoison . post ( "localhost:4002 /post" , { :stream , enumerable } , headers )
293293
294294 assert_response ( response , fn response ->
295295 assert Jason . decode! ( response . body ) [ "json" ] == expected
296296
297297 assert Request . to_curl ( response . request ) ==
298298 { :ok ,
299- "curl -X POST -H 'Content-type: application/json' -d '{\" some\" :\" bytes\" }' http://localhost:8080 /post" }
299+ "curl -X POST -H 'Content-type: application/json' -d '{\" some\" :\" bytes\" }' http://localhost:4002 /post" }
300300 end )
301301 end
302302
@@ -312,7 +312,7 @@ defmodule HTTPoisonTest do
312312 |> Kernel . * ( buffer_size )
313313 |> Kernel . trunc ( )
314314
315- resp = HTTPoison . get ( "localhost:8080 /stream/20" , [ ] , max_body_length: max_length )
315+ resp = HTTPoison . get ( "localhost:4002 /stream/20" , [ ] , max_body_length: max_length )
316316
317317 assert_response ( resp , fn response ->
318318 assert byte_size ( response . body ) <= expected_length
0 commit comments