Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8882715
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T20:38:54+00:00 2026-06-14T20:38:54+00:00

I figured out the hard way that it isn’t possible to add more headers

  • 0

I figured out the hard way that it isn’t possible to add more headers to an HttpServletResponse after beginning to write the response body to the output buffer, which, I guess in some random universe could make sense even though everything is still just buffered in memory.

Now the question is: Is there some trick to circumvent this somehow? Clearly, since the function resetBuffer() is available, which allows clearing of the content body without clearing the headers, there must be some way for the HttpServletResponse object to return to the state where writing more headers was possible. Is there, for example, a way to read the content body, clearing it with resetBuffer(), setting more headers, and then restoring the content body?

Aside:
The reason I would like do this is so I can add a header as the preferably very last step in my servlet, which tells me how long the server was busy processing the request.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T20:38:55+00:00Added an answer on June 14, 2026 at 8:38 pm

    Your only choice is to buffer the response body yourself; when body is finished, you then add the header, then write the body.

    The funny thing is, HTTP/1.1 has a way to ship a header after the response body, by using trailer in chunked encoding, but nobody implements that, so don’t bother.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I figured out that a constant literal get's placed in the data segment of
I figured out that CUDA does not work in 64bit mode on my mac
I figured out that of course . and SPACE aren't allowed. Are there other
I've learned the hard way that regexes cannot adequately parse html, prior to finding
Having a hard time figuring out the best way to go about this. What
I'm having hard time trying to figure out how to auto-save user data in
I am finding it really hard to figure out why we need a DEP!
I'm having a real hard time trying to figure out how to fix this
This really shouldn't be hard, I just can't figure out how to do it.
I am having one heck of a hard time trying to figure this out.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.