301 redirect: Why is the connection closed?

I learned how to use Connection: close when doing 301 redirects in Java

 response.setStatus(301); response.setHeader("Location", "http://www.example.com/"); response.setHeader("Connection", "close"); 

Why are we doing this? Why not omit the last line?

I have seen this in at least three examples, including this one: http://www.pardontheinformation.com/2010/09/java-servlet-jsp-301-and-302-redirect.html

I have never seen the last line omitted.

+6
source share
1 answer

If your redirect points to another server, the browser will have to use a different connection anyway, so you just tell the browser that it probably won't need to contact the current server again for this page. However, if your redirect points to the same server, I see no reason to close the connection.

+9
source

Source: https://habr.com/ru/post/892167/


All Articles