The transfer-length of a message is the length of the message-body as it appears in the message; that is, after any transfer-codings have been applied. When a message-body is included with a message, the transfer-length of that body is determined by one of the following (in order of precedence): 1.Any response message which "MUST NOT" include a message-body (such as the 1xx, 204, and 304 responses and any response to a HEAD request) is always terminated by the first empty line after the header fields, regardless of the entity-header fields present in the message. 2.If a Transfer-Encoding header field (section 14.41) is present and has any value other than "identity", then the transfer-length is defined by use of the "chunked" transfer-coding (section 3.6), unless the message is terminated by closing the connection. 3.If a Content-Length header field (section 14.13) is present, its decimal value in OCTETs represents both the entity-length and the transfer-length. The Content-Length header field MUST NOT be sent if these two lengths are different (i.e., if a Transfer-Encoding 4.If the message uses the media type "multipart/byteranges", and the transfer-length is not otherwise specified, then this self- delimiting media type defines the transfer-length. This media type MUST NOT be used unless the sender knows that the recipient can parse it; the presence in a request of a Range header with multiple byte- range specifiers from a 1.1 client implies that the client can parse multipart/byteranges responses. 5.By the server closing the connection. (Closing the connection cannot be used to indicate the end of a request body, since that would leave no possibility for the server to send back a response.) For compatibility with HTTP/1.0 applications, HTTP/1.1 requests containing a message-body MUST include a valid Content-Length header field unless the server is known to be HTTP/1.1 compliant. If a request contains a message-body and a Content-Length is not given, the server SHOULD respond with 400 (bad request) if it cannot determine the length of the message, or with 411 (length required) if it wishes to insist on receiving a valid Content-Length. All HTTP/1.1 applications that receive entities MUST accept the "chunked" transfer-coding (section 3.6), thus allowing this mechanism to be used for messages when the message length cannot be determined in advance. Messages MUST NOT include both a Content-Length header field and a non-identity transfer-coding. If the message does include a non- identity transfer-coding, the Content-Length MUST be ignored. When a Content-Length is given in a message where a message-body is allowed, its field value MUST exactly match the number of OCTETs in the message-body. HTTP/1.1 user agents MUST notify the user when an invalid length is received and detected. Chunked transfer encoding is a data transfer mechanism in the Hypertext Transfer Protocol (HTTP) that allows HTTP data to be reliably delivered between a web server and a clientapplication, usually a web browser, without knowing in advance of transmission the size of the entire message body. This is achieved by splitting the data payload of the message in small parts (chunks) and transmitting with each chunk its size. The data transfer is terminated by a final chunk of length zero. This makes it possible to transmit dynamically generated content in web pages. The chunked method is only available in version 1.1 of the HTTP protocol (HTTP/1.1). Without chunked transfer encoding, the size of data delivered in HTTP responses must be indicated by the Content-Length header If a Transfer-Encoding field with a value of chunked is specified in an HTTP message (either a request sent by a client or the response from the server), the body of the message consists of an unspecified number of chunks, a terminating last-chunk, an optional trailer of entity-header fields, and a final CRLF sequence. Each chunk starts with the number of octets of the data it embeds expressed in hexadecimal followed by optional parameters (chunk extension) and a terminating CRLF (carriage returnand line feed) sequence, followed by the chunk data. The chunk is terminated by CRLF. If chunk extensions are provided, the chunk size is terminated by a semicolon followed with the extension name and an optional equal sign and value. The last chunk is a zero-length chunk, with the chunk size coded as 0, but without any chunk data section. The final chunk may be followed by an optional trailer of additional entity-header fields that are normally delivered in the HTTP header to allow the delivery of data that can only be computed after all chunk data has been generated. The sender may indicate in a Trailer header field which additional fields it will send in the trailer after the chunks. The first two chunks contain explicit \r\n characters in the chunk data. The response ends with a zero-length last chunk: "0\r\ header field is present). If a message is received with both a Transfer-Encoding header field and a Content-Length header field, the latter MUST be ignored. A range header might be forwarded by a 1.0 proxy that does not understand multipart/byteranges; in this case the server MUST delimit the message using methods defined in items 1,3 or 5 of this section.
Chunked transfer encoding
Format
[edit]Example
[edit]Encoded response
HTTP/1.1 200 OK Content-Type: text/plain Transfer-Encoding: chunked 25 This is the data in the first chunk 1C and this is the second one 3 con 8 sequence 0 [edit]Anatomy of encoded response
"This is the data in the first chunk\r\n" (37 chars => hex: 0x25) "and this is the second one\r\n" (28 chars => hex: 0x1C) "con" (3 chars => hex: 0x03) "sequence" (8 chars => hex: 0x08) [edit]Decoded data
This is the data in the first chunk and this is the second one consequence
Search this Blog:
Http Message Length
Http Message Overview
Http Status Codes
Status Codes
HTTP status codes are returned by web servers to describe if and how a request was processed. The codes are grouped by the first digit:
1xx - Informational
Any code starting with '1' is an intermediate response and indicates that the server has received the request but has not finished processing it. For example, IIS initially replies with 100 Continue when it receives a POST request and then with 200 OK once it has been processed
2xx - Successful
These codes are used when a request has been successfully processed. For example, the value 200 is used when the requested resource is being returned to the HTTP client in the body of the response message.
3xx - Redirection
Codes starting with a '3' indicate that the request was processed, but the browser should get the resource from another location. Some examples are:
| 302 | The requested resource has been temporarily moved and the browser should issue a request to the URL supplied in the Location response header. |
| 304 | The requested resource has not been modified and the browser should read from its local cache instead. The Content-Length header will be zero or absent because content is never returned with a 304 response |
4xx - Client Error
The server returns these codes when they is a problem with the client's request. Here are some examples:
| 401 | Anonymous clients are not authorized to view the requested content and must provide authentication information in the WWW-Authenticate request header. |
| 404 | The requested resource does not exist on the server |
5xx - Server Error
A status code starting with the digit 5 indicates that an error occurred on the server while processing the request. For example:
| 500 | An internal error occurred on the server. This may be because of an application error or configuration problem |
| 503 | The service is currently unavailable, perhaps because of essential maintenance or overloading |
Http Authentication
Here is a typical transaction between an HTTP client and an HTTP server running on the local machine (localhost). It comprises the following steps.
1. The client asks for a page that requires authentication but does not provide a user name and password. Typically this is because the user simply entered the address or followed a link to the page.
2. The server responds with the 401 response code and provides the authentication realm.
3. At this point, the client will present the authentication realm (typically a description of the computer or system being accessed) to the user and prompt for a user name and password. The user may decide to cancel at this point.
4. Once a user name and password have been supplied, the client adds an authentication header (with value base64encode(username+":"+password)) to the original request and re-sends it.
5. In this example, the server accepts the authentication and the page is returned. If the user name is invalid or the password incorrect, the server might return the 401 response code and the client would prompt the user again.
Note: A client may pre-emptively send the authentication header in its first request, with no user interaction required.
Http Encoding
When an HTTP client is reading a response message from a server it needs to know when it has reached the end of the message. This is particularly important with persistent (keep alive) connections, because a connection can only be re-used by another HTTP transaction after the response message has been fully received. The following sections describe the four ways in which an HTTP server can indicate the end of the response message:
Connection Closed by Server
The connection can be closed at the end of the response message by the server, but this prevents connections being re-used.
Content-Length Header
The length of the content after the response headers can be specified in bytes with the Content-Length header
Implied Content Length
Some types of responses, such as 304, are defined to never have content and therefore the client can assume that the response message is terminated by the double CRLF after the headers.
Chunked Encoding
The content can be broken up into a number of chunks; each of which is prefixed by its size in bytes. A zero size chunk indicates the end of the response message. If a server is using chunked encoding it must set theTransfer-Encoding header to "chunked".
Chunked encoding is useful when a large amount of data is being returned to the client and the total size of the response may not be known until the request has been fully processed. An example of this is generating an HTML table of results from a database query. If you wantedto use the Content-Length header you would have to buffer the whole result set before calculating the total content size. However, with chunked encoding you could just write the data one row at a time and write a zero sized chunk when the end of the query was reached.
ref:
Http Wiki - http://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol
Http header fields - http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html
How to find ed of Http response - http://www.httpwatch.com/
HttpMessage structure - http://web-sniffer.net/
Http Message - http://www.w3.org/Protocols/
Http Authentication – http://en.wikipedia.org/wiki/Basic_access_authentication
HTTP Status Codes and Errors -http://www.httpwatch.com/httpgallery/errors/
http 1.1 RFC - http://www.w3.org/Protocols/rfc2616/rfc2616.html
http over TLS RFC - http://tools.ietf.org/html/rfc2818
ssl 3.0 RFC - http://tools.ietf.org/html/draft-ietf-tls-ssl-version3-00
