1
%% The contents of this file are subject to the Mozilla Public License
2
%% Version 1.1 (the "License"); you may not use this file except in
3
%% compliance with the License. You may obtain a copy of the License
4
%% at http://www.mozilla.org/MPL/
6
%% Software distributed under the License is distributed on an "AS IS"
7
%% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
8
%% the License for the specific language governing rights and
9
%% limitations under the License.
11
%% The Original Code is RabbitMQ.
13
%% The Initial Developer of the Original Code is VMware, Inc.
14
%% Copyright (c) 2010-2013 VMware, Inc. All rights reserved.
17
-module(rabbit_web_dispatch_util).
19
-export([parse_auth_header/1]).
20
-export([relativise/2]).
22
parse_auth_header(Header) ->
25
Str = base64:mime_decode_to_string(Base64),
26
case string:chr(Str, $:) of
28
N -> [list_to_binary(string:sub_string(Str, 1, N - 1)),
29
list_to_binary(string:sub_string(Str, N + 1))]
35
relativise("/" ++ F, "/" ++ T) ->
36
From = string:tokens(F, "/"),
37
To = string:tokens(T, "/"),
38
string:join(relativise0(From, To), "/").
40
relativise0([H], [H|_] = To) ->
42
relativise0([H|From], [H|To]) ->
43
relativise0(From, To);
44
relativise0(From, []) ->
45
lists:duplicate(length(From), "..");
46
relativise0([_|From], To) ->
47
lists:duplicate(length(From), "..") ++ To;
48
relativise0([], To) ->