HTTP Status: 100 Continue

Tue, 22 Apr 2008 20:26 UTC

As a self-described HTTP status code pedant and an architect of RESTful Web services, I’ve spent a great deal of time researching and thinking about the proper use of HTTP status codes in Web applications. It occurs to me that many people use status codes in their applications in ways that I find improper, so I’ve decided to start up a series of blog posts to talk about select status codes and how they might appropriately fit within your Web applications, specifically in a RESTful manner. Consider these “Ben’s HTTP Status Codes Best Practices.”

I won’t be covering these status codes in any particular order. However, the first code up is 100 Continue merely because I’ve been thinking about it lately.

The 100 Continue status code is an informational response that tells the client application it can continue sending the request. In short, the client can make an abbreviated request of the service to check whether or not it should continue making the full request. The service can then respond either “yes” (100 Continue) or “no” (417 Expectation Failed) with an explanation of why not. In RESTful Web Services, Richardson and Ruby refer to this as a “look-before-you-leap” (LBYL) request.

This is helpful in situations where the client might want to post or put a very large file to the service but wants to ensure that the service will accept it before actually sending the file. Consider the following request:

POST /content/videos HTTP/1.1
Host: media.example.org
Content-Type: video/mp4
Content-Length: 105910000
Authorization: Basic bWFkZTp5b3VfbG9vaw==
Expect: 100-continue

In this case, the client is attempting to post an MPEG-4 video that is 101MB. The client sends this request to your service without the video in the body, and it includes the Expect: 100-continue header. Let’s say your service limits uploads to 100MB. In that case, you would return a 417 Expectation Failed including a reason for the failure in the body of the response.

By now, you can probably see how this can be extended to apply to any of the other headers. For example, a client can try a POST or a PUT request first just to see if its authorization succeeds. If it does, your service would return 100, letting the client know it may proceed with the request. Likewise, the client might want to determine whether the service will accept a video/mp4 file before sending it. The list goes on.

It should be noted that the service shouldn’t require the client to use a LBYL request, but it can be helpful to a client so that it doesn’t attempt to send something that would fail at the service anyway.

I’m considering implementing these kinds of responses in a service I’m building, so I’ll let you know how it goes. :-)


6 Responses to “HTTP Status: 100 Continue”

Great post! You always enlighten me on things I take for granted… like http status codes!

They seem so hidden and untouchable, and you just want to use the standard 300/404/500…

The uses for some of them are very intriguing, and at least this one, 100, can significantly reduce overhead… instead of sending that 100mb file each time, then verifying details.. you can now verify before sending! GENIUS.

Comment by Christian Flickinger
Wed, 23 Apr 2008 at 2:06 UTC | Permalink

Keep going Ben, HTTP is a wonderfull and powerfull protocol, show us what it can do in real world ! ;-)
(Chris Shifflet’s HTTP developer’s Handbook is very nice)

Comment by julien-pauli
Wed, 23 Apr 2008 at 10:01 UTC | Permalink

Amazon’s S3 service uses this (if you want to play around with something in the wild).

Comment by Richard Harrison
Wed, 23 Apr 2008 at 23:59 UTC | Permalink

Can use 100 in PHP ?
As I know, PHP will save the file uploaded to /tmp first whatever u do
How to check “Content-Length” before the file saved?

Comment by Ralf Jones
Mon, 28 Apr 2008 at 11:33 UTC | Permalink

Ralf, I recommend you read the section in the PHP manual on the use of the header() function. In short, if you need to send the 100 Continue code, you may do so like this:

header(‘HTTP/1.1 100 Continue’);

If you are building a client application and need to check for the 100 Continue and other headers in a response received from the server, you can you curl, fsockopen, or something like Zend_Http.

Be aware that the Content-Length header cannot be trusted. The value it contains should only be considered for informational purposes and may not be the actual size of the uploaded file. However, with a request containing an Expect: 100-continue header, there won’t be a file uploaded, so you have only the Content-Length header to go by for determining whether or not to tell the client to continue sending the full request.

Comment by Ben Ramsey
Mon, 28 Apr 2008 at 14:30 UTC | Permalink

Hi,

I was wondering if there was a response status to allow a large file to be “served” in parts and in just one response?

I need a way to do this and I’d be grateful if the pedant offers succor :)

thanks!

Comment by Akki
Wed, 30 Apr 2008 at 14:02 UTC | Permalink

Leave a Comment

XHTML: You can use these tags:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>
APPROVAL: Comments may require approval. Please be patient.