whats the correct way to pass connection keep-alive response header in spring mvc

HI,
I am making a java mvc web application. I saw some similar application written in nodejs..
while checking the header content through network tools i found that the application had following headers
which my application was not having :

Response Headers :
---------------------
Connection:keep-alive
Date:Mon, 28 Sep 2015 12:02:18 GMT
ETag:W/"248a-0GOyw391ZfJ8sSP+/ysYOg"
X-Powered-By: Express

General
---------------
Remote Address:[::1]:8080
Request URL:http://localhost:8080/
Request Method:GET
Status Code:304 Not Modified

Request Headers
-------------------
one extra param :
If-None-Match:W/"248a-0GOyw391ZfJ8sSP+/ysYOg"

Open in new window


The two things i notice is has keep-alive in its header.
so i am wondering if i should also put keep-alive in my response.
I am thinking of just adding a line :
    response.addHeader("Connection", "keep-alive");
Is that the correct way ? will it work ?


The other thing i noticed is that its passing : Status Code:304 Not Modified
whereas by default my application is passing 200.
should i pass 304 ??

Thanks
Rohit BajajAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

mccarlIT Business Systems Analyst / Software DeveloperCommented:
"keep-alive" connections aren't really the domain of the Spring layer. That is up to the underlying servlet/web container (ie. Tomcat, Glassfish, JBoss, etc) to determine if/when to send those headers. Also, because it is probably not JUST a case of setting that header for the functionality to work. I would recommend investigating this issue in the context of the servlet/web container that you are using.

Regarding status code 304, it is a lot more complicated than just sending a different code. You need to understand the reasoning behind those status codes. Notice the other headers that you posted above, in particular the "Etag" and "If-None-Match" headers. This is all to do with response caching, ie. if the response hasn't changed from one sent previously, don't resend it (hence the 304 Not Modified status). You should probably read up on ETag's and how they are supported in Spring.


Also, I wouldn't worry about either of these two issues (keep-alive and etags) at an early stage of a project (which I believe you are at at the moment). Get it working correctly first, and then worry about optimizations like these.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Rohit BajajAuthor Commented:
Hmm,
yes thanks.. i will look up things.
Also actually the project which i am working on is already written in node.js .
what my task is to convert it to spring mvc. which i have done mostly.
So i am running both projects and matching if there are any differences in them.
Thats how i found that my web pages were not having those headers and the project was having.
So i have to bring both in line.
0
mccarlIT Business Systems Analyst / Software DeveloperCommented:
So i have to bring both in line.

Who said that you have to? I'm not saying that you don't but it may be that you don't have to worry. You are moving from node.js to Spring, so there are going to be differences anyway, and you may be getting hung up on these small things for no real end purpose.

Anyway, as I said, "keep-alive" is definitely 100% not something you should be catering for in your code. Look into whatever web/servlet container you are using.

And "ETag" support is not necessarily a simple add on where you can just set a few headers and your done. If you end up wanting/needing to add support for it, it will be something that will most likely affect a LOT of your project. Controllers, daos, models could all require changes to fully support caching and ETags.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Web Applications

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.