Supporting protocol'less URL's
I've run into some issues trying to make a request to a protocol'less URL:
URL = <<"//example.com/someimage.gif">>.
hackney:get(URL, [], <<>>, [{follow_redirect, true}]).
this results in the error message:
** exception error: no case clause matching []
in function hackney_url:parse_netloc/2 (src/hackney_url.erl, line 192)
in call from hackney:request/5 (src/hackney.erl, line 332)
i guess we could solve this by making a modification to the parse_url/1 function in hackney_url.erl something like the following:
parse_url(<<"//", Rest/binary>>) ->
parse_url(Rest, #hackney_url{transport=hackney_tcp, scheme=http});
what are your thoughts on this?
hrm hackney_url doesn't handle such cases right now. This can be added I guess. What is the usecase for it ? (to see if any other API change is needed).
URLs like this 'generally' only appear in html and common browser behavior is to inherit the scheme from the page they're being displayed on. IE when page is https the URL is interpreted as https
This is probably pertinent should URLs in such form be received in Location: header. Yes, it's not strictly valid, but maybe is should be supported (Inherit the scheme from the previous URL)
EG:
https://example.com -> 301 Location: //www.example.com -> https://www.example.com
http://example.com -> 301 Location: //www.example.com -> http://www.example.com