diff --git a/fixture/vcr_cassettes/example_httpc_request_4.json b/fixture/vcr_cassettes/example_httpc_request_4.json
index 2d66b41..bbccee2 100644
--- a/fixture/vcr_cassettes/example_httpc_request_4.json
+++ b/fixture/vcr_cassettes/example_httpc_request_4.json
@@ -8,19 +8,21 @@
"httpc_options": [],
"http_options": []
},
+ "request_body": "",
"url": "http://example.com"
},
"response": {
"body": "\n\n
\n Example Domain\n\n \n \n \n \n\n\n\n\n
Example Domain
\n
This domain is established to be used for illustrative examples in documents. You may use this\n domain in examples without prior coordination or asking for permission.
\n
More information...
\n
\n\n\n",
"headers": {
"cache-control": "max-age=604800",
- "date": "Sun, 30 Nov 2014 11:15:00 GMT",
+ "date": "Tue, 12 Jan 2016 13:12:40 GMT",
"accept-ranges": "bytes",
"etag": "\"359670651\"",
- "server": "ECS (cpm/F9FC)",
+ "server": "ECS (ewr/15BD)",
+ "vary": "Accept-Encoding",
"content-length": "1270",
"content-type": "text/html",
- "expires": "Sun, 07 Dec 2014 11:15:00 GMT",
+ "expires": "Tue, 19 Jan 2016 13:12:40 GMT",
"last-modified": "Fri, 09 Aug 2013 23:54:35 GMT",
"x-cache": "HIT",
"x-ec-custom-error": "1"
diff --git a/fixture/vcr_cassettes/example_httpc_request_4_additional_options.json b/fixture/vcr_cassettes/example_httpc_request_4_additional_options.json
new file mode 100644
index 0000000..a0a3033
--- /dev/null
+++ b/fixture/vcr_cassettes/example_httpc_request_4_additional_options.json
@@ -0,0 +1,45 @@
+[
+ {
+ "request": {
+ "body": "",
+ "headers": {
+ "Content-Type": "text/html"
+ },
+ "method": "get",
+ "options": {
+ "httpc_options": {
+ "body_format": "binary"
+ },
+ "http_options": {
+ "connect_timeout": "3000",
+ "timeout": "5000"
+ }
+ },
+ "request_body": "",
+ "url": "http://example.com"
+ },
+ "response": {
+ "body": "\n\n\n Example Domain\n\n \n \n \n \n\n\n\n\n
Example Domain
\n
This domain is established to be used for illustrative examples in documents. You may use this\n domain in examples without prior coordination or asking for permission.
\n
More information...
\n
\n\n\n",
+ "headers": {
+ "cache-control": "max-age=604800",
+ "date": "Tue, 12 Jan 2016 13:12:40 GMT",
+ "accept-ranges": "bytes",
+ "etag": "\"359670651\"",
+ "server": "ECS (ewr/15BD)",
+ "vary": "Accept-Encoding",
+ "content-length": "1270",
+ "content-type": "text/html",
+ "expires": "Tue, 19 Jan 2016 13:12:40 GMT",
+ "last-modified": "Fri, 09 Aug 2013 23:54:35 GMT",
+ "x-cache": "HIT",
+ "x-ec-custom-error": "1"
+ },
+ "status_code": [
+ "HTTP/1.1",
+ 200,
+ "OK"
+ ],
+ "type": "ok"
+ }
+ }
+]
\ No newline at end of file
diff --git a/lib/exvcr/adapter/httpc.ex b/lib/exvcr/adapter/httpc.ex
index b9fef36..9b18372 100644
--- a/lib/exvcr/adapter/httpc.ex
+++ b/lib/exvcr/adapter/httpc.ex
@@ -35,14 +35,13 @@ defmodule ExVCR.Adapter.Httpc do
Generate key for searching response.
"""
def generate_keys_for_request(request) do
- if Enum.count(request) <= 2 do
- [url: Enum.fetch!(request, 0), method: :get]
- else
- url = Enum.fetch!(request, 1) |> elem(0)
- method = Enum.fetch!(request, 0)
- request_body = Enum.fetch(request, 3) |> parse_request_body
-
- [url: url, method: method, request_body: request_body]
+ case request do
+ [method, {url, _} | _] ->
+ [url: url, method: method, request_body: nil]
+ [method, {url, _, _, body} | _] ->
+ [url: url, method: method, request_body: body]
+ [url | _] ->
+ [url: url, method: :get, request_body: nil]
end
end
diff --git a/test/adapter_httpc_test.exs b/test/adapter_httpc_test.exs
index 7b6f25a..ce1032c 100644
--- a/test/adapter_httpc_test.exs
+++ b/test/adapter_httpc_test.exs
@@ -25,6 +25,17 @@ defmodule ExVCR.Adapter.HttpcTest do
end
end
+ test "example httpc request/4 with additional options" do
+ use_cassette "example_httpc_request_4_additional_options" do
+ {:ok, {{_, 200, _reason_phrase}, _headers, body}} = :httpc.request(
+ :get,
+ {'http://example.com', [{'Content-Type', 'text/html'}]},
+ [connect_timeout: 3000, timeout: 5000],
+ body_format: :binary)
+ assert to_string(body) =~ ~r/Example Domain/
+ end
+ end
+
test "example httpc request error" do
use_cassette "example_httpc_request_error" do
{:error, {reason, _detail}} = :httpc.request('http://invalidurl')