Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files
Add handy params_from_header_string/1.
For use when decoding the OAuth's "Authorization" header.

Signed-off-by: Tim Fletcher <tim@tfletcher.com>
  • Loading branch information
Jason Davies authored and Tim Fletcher committed Jul 19, 2009
1 parent 5625976 commit 8bf26038f9b65a88c4ce5f7965da84be29523c0a
Showing 1 changed file with 10 additions and 1 deletion.
@@ -1,7 +1,8 @@
-module(oauth_uri).

-export([normalize/1, calate/2, encode/1]).
-export([params_from_string/1, params_to_string/1, params_to_header_string/1]).
-export([params_from_string/1, params_to_string/1,
params_from_header_string/1, params_to_header_string/1]).

-import(lists, [concat/1]).

@@ -37,6 +38,14 @@ normalize(Scheme, UserInfo, Acc) ->
params_to_header_string(Params) ->
intercalate(", ", [concat([encode(K), "=\"", encode(V), "\""]) || {K, V} <- Params]).

params_from_header_string(String) ->
[param_from_header_string(Param) || Param <- re:split(String, ",\\s*", [{return, list}])].

param_from_header_string(Param) ->
[Key, QuotedValue] = string:tokens(Param, "="),
Value = string:substr(QuotedValue, 2, length(QuotedValue) - 2),
{decode(Key), decode(Value)}.

params_from_string(Params) ->
[param_from_string(Param) || Param <- string:tokens(Params, "&")].

0 comments on commit 8bf2603

Please sign in to comment.