title: Erlang Get the final redirected URL
body: <p>As given in <a href="https://stackoverflow.com/questions/12671352/follow-the-end-url-in-erlang">this</a> question, I used below method for finding the final redirected URL as</p>
  
  <pre><code>URL="http://mail.google.com",
  HTTPOpts = [{autoredirect, false}],
  perform_request(URL) -&gt;
  case httpc:request(get, {URL, [{"User-Agent", "Mozilla"}]}, HTTPOpts, []) of
     {ok, {{_, Code, _}, Headers, Body}}  when Code == 200  -&gt;
  
         %%code_to_process_the_URL%%
  
     {ok, {{_, Code, _}, Headers, _}}  when Code &lt; 310 , Code &gt;= 300 -&gt;
  
       NewURL=proplists:get_value("location", Headers),
       perform_request(NewURL)
       end
  </code></pre>
  
  <p>This works fine for other URLs but it faces issues with <code>URL = https://mail.google.com</code> as its first location header is <code>location = /mail/</code> which is not a valid URL and I get a empty page.</p>
  
  <p>I also generated output using <code>GET</code> command to verify this on terminal.</p>
  
  <p>output:</p>
  
  <pre><code>mandeep@mandeep-Inspiron-5447:~$ GET -S -d -e http://mail.google.com
  GET http://mail.google.com
  301 Moved Permanently
  Cache-Control: private, max-age=0
  Connection: close
  Date: Tue, 21 Feb 2017 11:56:14 GMT
  Accept-Ranges: none
  Location: /mail/
  Server: GSE
  Vary: Accept-Encoding
  Content-Type: text/html; charset=UTF-8
  Expires: Tue, 21 Feb 2017 11:56:14 GMT
  Client-Date: Tue, 21 Feb 2017 11:55:30 GMT
  Client-Peer: 216.58.197.69:80
  Client-Response-Num: 1
  Title: Moved Permanently
  X-Content-Type-Options: nosniff
  X-Frame-Options: SAMEORIGIN
  X-XSS-Protection: 1; mode=block
  
  GET http://mail.google.com/mail/
  302 Moved Temporarily
  Cache-Control: private, max-age=0
  Connection: close
  Date: Tue, 21 Feb 2017 11:56:15 GMT
  Accept-Ranges: none
  Location: https://mail.google.com/mail/
  Server: GSE
  Vary: Accept-Encoding 
  Content-Type: text/html; charset=UTF-8
  Expires: Tue, 21 Feb 2017 11:56:15 GMT
  Client-Date: Tue, 21 Feb 2017 11:55:30 GMT
  Client-Peer: 172.217.26.165:80
  Client-Response-Num: 1
  Title: Moved Temporarily
  X-Content-Type-Options: nosniff
  X-Frame-Options: SAMEORIGIN
  X-XSS-Protection: 1; mode=block
  
  GET https://mail.google.com/mail/
  302 Moved Temporarily
  Cache-Control: no-cache, no-store, max-age=0, must-revalidate
  Connection: close
  Date: Tue, 21 Feb 2017 11:56:21 GMT
  Pragma: no-cache
  Accept-Ranges: none
  Location: https://accounts.google.com/ServiceLogin?service=mail&amp;passive=true&amp;rm=false&amp;continue=https://mail.google.com/mail/&amp;ss=1&amp;scc=1&amp;ltmpl=default&amp;ltmplcache=2&amp;emr=1&amp;osid=1
  Server: GSE
  Vary: Accept-Encoding
  Content-Type: text/html; charset=UTF-8
  Expires: Mon, 01 Jan 1990 00:00:00 GMT
  Alt-Svc: quic=":443"; ma=2592000; v="35,34"
  Client-Date: Tue, 21 Feb 2017 11:55:36 GMT
  Client-Peer: 216.58.197.69:443
  Client-Response-Num: 1
  Client-SSL-Cert-Issuer: /C=US/O=Google Inc/CN=Google Internet
  Authority G2
  Client-SSL-Cert-Subject: /C=US/ST=California/L=Mountain View/O=Google        Inc/CN=mail.google.com
  Client-SSL-Cipher: ECDHE-ECDSA-AES128-GCM-SHA256
  Client-SSL-Socket-Class: IO::Socket::SSL
  Title: Moved Temporarily
  X-Content-Type-Options: nosniff 
  X-Frame-Options: SAMEORIGIN
  X-XSS-Protection: 1; mode=block
  
  GET https://accounts.google.com/ServiceLogin?service=mail&amp;passive=true&amp;rm=false&amp;continue=https://mail.google.com/mail/&amp;ss=1&amp;scc=1&amp;ltmpl=default&amp;ltmplcache=2&amp;emr=1&amp;osid=1
  200 OK
  Cache-Control: no-cache, no-store
  Connection: close
  Date: Tue, 21 Feb 2017 11:56:22 GMT
  Pragma: no-cache
  Server: GSE
  Content-Type: text/html; charset=UTF-8
  Expires: Mon, 01-Jan-1990 00:00:00 GMT
  Alt-Svc: quic=":443"; ma=2592000; v="35,34"
  Client-Date: Tue, 21 Feb 2017 11:55:38 GMT
  Client-Peer: 172.217.26.173:443
  Client-Response-Num: 1
  Client-SSL-Cert-Issuer: /C=US/O=Google Inc/CN=Google Internet     Authority G2
  Client-SSL-Cert-Subject: /C=US/ST=California/L=Mountain View/O=Google    Inc/CN=accounts.google.com
  Client-SSL-Cipher: ECDHE-RSA-AES128-SHA
  Client-SSL-Socket-Class: IO::Socket::SSL
  Client-Transfer-Encoding: chunked
  Link: &lt;https://www.google.com/gmail/&gt;; rel="canonical"
  Set-Cookie:   GAPS=1:uiUyF1S0WckgUUlRhZmrUeuRVCgCiA:9vKBlzT8ecd7l7Ob;Path=/;Expires=Thu,    21-Feb-2019 11:56:22 GMT;Secure;HttpOnly;Priority=HIGH
  Set-Cookie: GALX=mfArYRFLcco;Path=/;Secure
  Strict-Transport-Security: max-age=10893354; includeSubDomains
  Title: Gmail
  X-Auto-Login:realm=com.google&amp;args=service%3Dmail%26continue%3Dhttps%253A%252F%252Fmail.google.com%252Fmail%252F
  X-Content-Type-Options: nosniff
  X-Frame-Options: DENY
  X-Meta-Charset: utf-8
  X-Meta-Description: Gmail is email that's intuitive, efficient, and
  useful. 15 GB of storage, less spam, and mobile access.
  X-Meta-Google-Site-Verification: LrdTUW9psUAMbh4Ia074-BPEVmcpBxF6Gwf0MSgQXZs
  X-Meta-Viewport: width=300, initial-scale=1
  X-XSS-Protection: 1; mode=block
  </code></pre>
  
  <p>How this issue can be resolved?</p>