Skip to content

Commit

Permalink
Merge branch 'srenatus-sr/www.w3.org'
Browse files Browse the repository at this point in the history
  • Loading branch information
willemdj committed Apr 22, 2016
2 parents 57de181 + ea618bd commit 40c4182
Showing 1 changed file with 14 additions and 11 deletions.
25 changes: 14 additions & 11 deletions src/erlsom_lib.erl
Original file line number Diff line number Diff line change
Expand Up @@ -828,8 +828,21 @@ findFile(Namespace, Location, IncludeFiles, IncludeDirs) ->
{getFile(Location, IncludeDirs), undefined}
end.

getFile("http://"++_ = URL, _) ->
httpGetFile(URL);
getFile("https://"++_ = URL, _) ->
case httpc:request(URL) of
httpGetFile(URL);
getFile(Location, IncludeDirs) ->
case filelib:is_file(Location) of
true ->
readImportFile(Location);
_ ->
%% debug(IncludeDirs),
findFileInDirs(Location, IncludeDirs)
end.

httpGetFile(URL) ->
case httpc:request(get, {URL, [{"user-agent", "erlsom"}]}, [], []) of
{ok,{{_HTTP,200,_OK}, _Headers, Body}} ->
toUnicode(Body);
{ok,{{_HTTP,RC,Emsg}, _Headers, _Body}} ->
Expand All @@ -840,18 +853,8 @@ getFile("https://"++_ = URL, _) ->
error_logger:error_msg("~p: http-request failed: ~p~n",
[?MODULE, Reason]),
{error, "failed to retrieve: "++URL}
end;
getFile(Location, IncludeDirs) ->
case filelib:is_file(Location) of
true ->
readImportFile(Location);
_ ->
%% debug(IncludeDirs),
findFileInDirs(Location, IncludeDirs)
end.



findFileInDirs(undefined, []) ->
throw({error, "Include file not found (undefined)"});
findFileInDirs(Location, []) ->
Expand Down

0 comments on commit 40c4182

Please sign in to comment.