• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Response Headers

 
Ravi Singh
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is it possible to set response headers after a response has been committed as I am under the impression that ALL response headers must be sent before the response body is sent?

e.g.
response.setHeader("headername", "headervalue");
response.flushBuffer();
response.setHeader("headername", "headervalue");
response.flushBuffer();
 
Sundar Gopal
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
once the response is committed we can't set the header. you have used flushBuffer() which commits the response which forces any content in the buffer to be written to the client. A call to this method automatically commits the response, meaning the status code and headers will be written.
 
HaoZhe Xu
Ranch Hand
Posts: 222
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think you can set several headers at one time, don't need to set it one by one.
 
Ravi Singh
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do all headers have to be sent before the response body is sent?
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13055
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do all headers have to be sent before the response body is sent?

Of course - at the TCP/IP level, the response is just a single stream of characters sent to the browser. The servlet API keeps the headers separate from the output buffer until the first buffer flush, but after that the headers have been written.
Bill
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic