benoitc / hackney

simple HTTP client in Erlang
Other
1.34k stars 427 forks source link

Getting 500 response for valid url #550

Closed idod closed 5 years ago

benoitc commented 5 years ago

can you provide more informations: logs, trace or anything that could help to reproduce the issue?

idod commented 5 years ago

Sorry, I got an error on hackney and not on curl. No I get it also on curl :) No issue.

idod commented 5 years ago

So there is an issue: when trying to get the url of "https://assets.superbalistcdn.co.za/500x720/filters:quality(75):format(jpg)/spree/product/s/p/spree2018september12picslgzh0650.jpg" with hacnkey I get an error, although it is working fine on curl / browser:

when getting with hackney: hackney:get(<<"https://assets.superbalistcdn.co.za/500x720/filters:quality(75):format(jpg)/spree/product/s/p/spree2018september12picslgzh0650.jpg">>). {ok,500, [{<<"Date">>,<<"Tue, 08 Jan 2019 14:11:53 GMT">>}, {<<"Content-Type">>,<<"text/html; charset=UTF-8">>}, {<<"Transfer-Encoding">>,<<"chunked">>}, {<<"Connection">>,<<"keep-alive">>}, {<<"Set-Cookie">>, <<"__cfduid=d8081ddfb7dd7ce93d45546477584bcc11546956713; expires=Wed, 08-Jan-20"...>>}, {<<"X-Varnish">>,<<"15930532">>}, {<<"Via">>,<<"1.1 varnish-v4, 1.1 google">>}, {<<"Alt-Svc">>,<<"clear">>}, {<<"CF-Cache-Status">>,<<"MISS">>}, {<<"X-Content-Type-Options">>,<<"nosniff">>}, {<<"Expect-CT">>, <<"max-age=604800, report-uri=\"https://report-uri.cloud"...>>}, {<<"Server">>,<<"cloudflare">>}, {<<"CF-RAY">>,<<"495f41806f2029dd-SEA">>}],

Ref<0.2804061591.1561329665.145241>}

When curl: curl -v "https://assets.superbalistcdn.co.za/500x720/filters:quality(75):format(jpg)/spree/product/s/p/spree2018september12picslgzh0650.jpg" -O /dev/null % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0* Trying 104.20.2.217...

aditrades commented 5 years ago

Happens to me too :-\

joeyfeldberg commented 5 years ago

If you remove the "filters:quality(75):format(jpg)" part of the URL it works, so might be a parser issue?

benoitc commented 5 years ago

@joeyfeldberg good catch

Hackney will normalize the URL and encode ( and ):

5> hackney_url:normalize(Url).
{hackney_url,hackney_ssl,https,
             <<"assets.superbalistcdn.co.za">>,
             <<"/500x720/filters:quality(75):format(jpg)/spree/product/s/p/spree2018september12picslgzh0650.jpg">>,
             <<"/500x720/filters:quality%2875%29:format%28jpg%29/spree/product/s/p/spree2018september12picsl"...>>,
             <<>>,<<>>,"assets.superbalistcdn.co.za",443,<<>>,<<>>}

Normally the server must decode it. Anyway as a temporary solution @idod if you don't want to en,code the Url you can pass your own function:

9> hackney:request(get, Url, [], [], [{path_encode_fun, fun(U) -> U end}]).
{ok,200,
    [{<<"Date">>,<<"Wed, 09 Jan 2019 09:13:52 GMT">>},
     {<<"Content-Type">>,<<"image/jpeg">>},
     {<<"Content-Length">>,<<"33101">>},
     {<<"Connection">>,<<"keep-alive">>}, 
     {<<"Set-Cookie">>,
      <<"__cfduid=dc4abf8a53694e4c9c40839736259fa0c1547025231; expires=Thu, 09-Jan-20"...>>},
     {<<"Expires">>,<<"Tue, 09 Apr 2019 09:13:52 GMT">>},
     {<<"Etag">>,
      <<"\"022e2364f299e640a24e5995a280ad35b9e6591b\"">>},
     {<<"Cache-Control">>,<<"public, max-age=7776000">>},
     {<<"X-Varnish">>,<<"16710304">>},
     {<<"Via">>,<<"1.1 varnish-v4, 1.1 google">>},
     {<<"Alt-Svc">>,<<"clear">>},
     {<<"CF-Cache-Status">>,<<"MISS">>},
     {<<"Accept-Ranges">>,<<"bytes">>},
     {<<"X-Content-Type-Options">>,<<"nosniff">>},
     {<<"Expect-CT">>,
      <<"max-age=604800, report-uri=\"https://"...>>},
     {<<"Server">>,<<"cloudflare">>},
     {<<"CF-RAY">>,<<"4965ca53c879a899-CDG">>}],
    #Ref<0.2882158659.3792961537.99124>}

I will figure about a better way to handle it.

benoitc commented 5 years ago

fixed in master via 4a501a0eb6adcce3c6ea3d90287fa8da18f5cd09