inets example missing ssl:start()

In Erlang -- HTTP Client, if I follow the instructions (without using a proxy because I don’t need a proxy here), erl hangs when making a request to http://www.erlang.org.

johnk@dirtynewcomputer:~$ erl
Erlang/OTP 26 [erts-14.0] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] [jit:ns]

Eshell V14.0 (press Ctrl+G to abort, type help(). for help)
1> inets:start().
ok
2> {ok, {{Version, 200, ReasonPhrase}, Headers, Body}} =
..       httpc:request(get, {"http://www.erlang.org", []}, [], []).

BREAK: (a)bort (A)bort with dump (c)ontinue (p)roc info (i)nfo
       (l)oaded (v)ersion (k)ill (D)b-tables (d)istribution
a

That’s because after this documentation was written, http://www.erlang.org now redirects to https://www.erlang.org, which requires ssl:start().

e.g.

johnk@dirtynewcomputer:~$ erl
Erlang/OTP 26 [erts-14.0] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] [jit:ns]

Eshell V14.0 (press Ctrl+G to abort, type help(). for help)
1> inets:start().
ok
2> ssl:start().
ok
3> {ok, {{Version, 200, ReasonPhrase}, Headers, Body}} = httpc:request(get, {"http://www.erlang.org", []}, [], []).
{ok,{{"HTTP/1.1",200,"OK"},
     [{"cache-control","public,max-age=0,must-revalidate"},
      {"date","Tue, 22 Aug 2023 22:21:43 GMT"},
      {"accept-ranges","bytes"},
      {"age","11450"},
      {"etag","\"1050519f47cb36b79741a041558c101d-ssl\""},
      {"server","Netlify"},
      {"content-length","19144"},
      {"content-type","text/html; charset=UTF-8"},
      {"strict-transport-security","max-age=31536000"},
      {"x-nf-request-id","01H8FNDT5CBS2Q7GZNXX92MD59"}],
     "<!DOCTYPE html>\n<html lang=\"en\">\n\n\n\n<head>\n    <meta charset=\"utf-8\">\n    <meta http-equiv=\"X-UA-Compatible\" content=\"IE=edge\">\n\n
...

Given that these days, more and more sites are moving to https-only mode, and redirecting http to https (like www.erlang.org does) should inets:start() actually include ssl:start(). or equivalent? Or just update the documentation for inets?

Thanks,

  • johnk
1 Like

It actually does redirect. httpc by default has autoredirect set to true, so it may appear that it’s not ,but if you set this to false

1> httpc:request(get, {"http://www.erlang.org", []}, [{autoredirect, false}], []).
{ok,{{"HTTP/1.1",301,"Moved Permanently"},
     [{"date","Tue, 22 Aug 2023 22:54:56 GMT"},
      {"location","https://www.erlang.org/"},
      {"server","Netlify"},
      {"content-length","38"},
      {"content-type","text/plain; charset=utf-8"},
      {"x-nf-request-id","01H8FQAM9AKAWYXX3GVW1VG43R"}],
     "Redirecting to https://www.erlang.org/"}}

:slight_smile:

Thanks Bryan,

My point is that the inets documentation of that example does not say anything about setting autoredirect to false, nor does it suggest to ssl:start() (which is what worked for me, and does follow the redirect, which I actually want).

Furthermore, the example would work, as written, if inets:start() also included ssl:start(), which is an intriguing (to me) possibility since so many sites these days redirect to https, and/or only offer their sites over https, so it could or even should be the default to start ssl at the same time as inets.

Cheers,

  • johnk
1 Like

Right, so perhaps there’s enhancements to make to the docs. To note, ssl should be started up for you, but if this isn’t clear, then perhaps it should be documented at least somewhat.