top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

What is the structure of the HTTP response ?

+3 votes
227 views
What is the structure of the HTTP response ?
posted Feb 13, 2015 by Dominic

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

2 Answers

+1 vote

The HTTP response headers contain information specific to the needs of the response, such as the location (used to redirect the client to a new URI). One of the more important response headers is WWW-Authenticate used in conjunction with status 401 (unauthorized). This is how web sites are able to prompt for usernames and passwords without using any backend processing logic (a browser user sees the browser prompting for a username and a password). This uses a challenge/response system. RFC 2617 outlines two methods for this authentication: basic (which uses cleartext usernames and passwords) and digest (which uses MD5 hashes). If you really want an exercise in learning the basics, it is a fun project to write your own implementation of HTTP authentication without using any libraries, just text processing and basic math to recreate the MD5 algorithm.
I did this a long time ago in Perl, and working on that project was how I learned the guts of HTTP so well.

HTTP response is a message sent by the server back to the client after having received and interpreted a request message. The first line of that message consists of the protocol version followed by a numeric status code and its associated textual phrase.

HttpResponse response = new BasicHttpResponse(HttpVersion.HTTP_1_1,
    HttpStatus.SC_OK, "OK");

System.out.println(response.getProtocolVersion());
System.out.println(response.getStatusLine().getStatusCode());
System.out.println(response.getStatusLine().getReasonPhrase());
System.out.println(response.getStatusLine().toString());

stdout >

HTTP/1.1
200
OK
HTTP/1.1 200 OK
answer Feb 13, 2015 by Amit Kumar Pandey
+1 vote

An HTTP response, like a request, has a three-part structure:

<HTTP-version> <status-code> <reason-phrase>

SOURCE CODE: describes the status of the response. It can be used to check if the request has been successfully completed. In case the request failed, the status code can be used to find out the reason behind the failure. If your servlet does not return a status code, the success status code, HttpServletResponse.SC_OK, is returned by default.

HTTP HEADERS: they contain more information about the response. For example, the headers may specify the date/time after which the response is considered stale, or the form of encoding used to safely transfer the entity to the user.

BODY: it contains the content of the response. The body may contain HTML code, an image, etc. The body consists of the data bytes transmitted in an HTTP transaction message immediately following the headers.

answer Feb 16, 2015 by Karthick.c
Similar Questions
0 votes

I have a requirement to monitor http request/response logs. We have a embedded Tomcat 7. Could you please point out the options available to do this?.
I'm already aware of the Access Log Valve ( http://www.tomcat.apache.org/tomcat-7.0-doc/config/valve.html#Access_Log_Valve ). But it can only log separate request headers and query params of the request body..
Would like to know if there is any better approach..

...