Skip to content

Commit fefbce7

Browse files
committed
process headers before checking the content-type
1 parent f5f79a3 commit fefbce7

File tree

2 files changed

+3
-4
lines changed

2 files changed

+3
-4
lines changed

lib/oauth2/response.ex

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,10 @@ defmodule OAuth2.Response do
2626

2727
@doc false
2828
def new(status_code, headers, body) do
29+
headers = process_headers(headers)
2930
%__MODULE__{
3031
status_code: status_code,
31-
headers: process_headers(headers),
32+
headers: headers,
3233
body: decode_response_body(body, content_type(headers))
3334
}
3435
end
@@ -41,8 +42,6 @@ defmodule OAuth2.Response do
4142
defp decode_response_body(" ", _type), do: ""
4243
defp decode_response_body(body, "application/x-www-form-urlencoded"),
4344
do: URI.decode_query(body)
44-
defp decode_response_body(body, "text/plain"),
45-
do: URI.decode_query(body)
4645
defp decode_response_body(body, type) do
4746
if serializer = Application.get_env(:oauth2, :serializers)[type] do
4847
serializer.decode!(body)

test/oauth2/access_token_test.exs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ defmodule OAuth2.AccessTokenTest do
1010
end
1111

1212
test "new with 'expires' param" do
13-
response = Response.new(200, [{"content-type", "text/plain"}], "access_token=abc123&expires=123")
13+
response = Response.new(200, [{"Content-Type", "application/x-www-form-urlencoded"}], "access_token=abc123&expires=123")
1414
token = AccessToken.new(response.body)
1515
assert token.access_token == "abc123"
1616
assert token.expires_at == 123

0 commit comments

Comments
 (0)