detergentex icon indicating copy to clipboard operation
detergentex copied to clipboard

https support

Open pmontrasio opened this issue 7 years ago • 0 comments

SOAP requests to https urls fails with {:error, :enoent}

I traced it back to src/detergent.erl in deps, which doesn't have pattern matching for URLs starting with https. It falls back to reading from a local file with the name of the URL, which doesn't exist. The code I'm seeing is

get_url_file("http://"++_ = URL) ->
    case httpc:request(URL) of
    {ok,{{_HTTP,200,_OK}, _Headers, Body}} ->
        {ok, Body};
    {ok,{{_HTTP,RC,Emsg}, _Headers, _Body}} ->
        error_logger:error_msg("~p: http-request got: ~p~n", [?MODULE, {RC, Emsg}]),
        {error, "failed to retrieve: "++URL};
    {error, Reason} ->
        error_logger:error_msg("~p: http-request failed: ~p~n", [?MODULE, Reason]),
        {error, "failed to retrieve: "++URL}
    end;
get_url_file("file://"++Fname) ->
    {ok, Bin} = file:read_file(Fname),
    {ok, binary_to_list(Bin)};
%% added this, since this is what is used in many WSDLs (i.e.: just a filename).
get_url_file(Fname) ->
    {ok, Bin} = file:read_file(Fname),
    {ok, binary_to_list(Bin)}.

However detergent at https://github.com/devinus/detergent/blob/master/src/detergent.erl has the same version of the dependency in detergentex (0.3.0) and does support https (https://github.com/devinus/detergent/blob/master/src/detergent.erl#L395).

get_url_file(URL) ->
    case xmerl_uri:parse(URL) of
        {http, _, _, _, _} -> get_remote_file(URL);
        {https, _, _, _, _} -> get_remote_file(URL);
        _Other -> get_local_file(URL)
end.

That was added in 2013 with https://github.com/devinus/detergent/commit/5354f1c82520666f5746aae1fbbec41331b52f4c#diff-c46a9580e05c152c0b037750f88eb760

It happens that detergentex is downloading an older detergent or some different fork. However https://hex.pm/packages/detergent links to https://github.com/devinus/detergent

I wonder if there is some dependency mismatch and if mix.exs could be updated to depend from the version at https://github.com/devinus/detergent

Thanks

pmontrasio avatar Dec 01 '17 11:12 pmontrasio