Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Determine size of HTTP Response?

Is there a way to determine the size of the HTTPServletResponse content? I read this get-size-of-http-response-in-java question but sadly where I work I do not have access to CommonsIO :(

The response content consists of a single complex object so I have considered writing it out to a temp file and then checking that file. This is not something I want to be doing as a diagnostic while the application is running in production though so want to avoid it if at all possible.

PS I read erickson's answer but it mentioned input streams I want to know the size of the object being written out... Would be really nice if the writeObject() method returned a number representing bytes written instead of void...

like image 615
BigMac66 Avatar asked Feb 03 '23 20:02

BigMac66


1 Answers

If you have access to the response header, you can read the Content-Length.

Here is a example of a response header:

(Status-Line):HTTP/1.1 200 OK
Connection:Keep-Alive
Date:Fri, 25 Mar 2011 16:26:56 GMT
Content-Length:728

Check this out: Header Field Definitions

like image 168
Rafael Colucci Avatar answered Feb 05 '23 10:02

Rafael Colucci