spray / spray-can

A low-overhead, high-performance, fully async HTTP 1.1 server and client library implemented entirely in Scala on top of Akka
http://spray.io
Apache License 2.0
153 stars 19 forks source link

spray-can should deal properly with the Expect: 100 Continue header #24

Closed dpratt closed 12 years ago

dpratt commented 12 years ago

According to the HTTP spec

Upon receiving a request which includes an Expect request-header field with the "100-continue" expectation, an origin server MUST either respond with 100 (Continue) status and continue to read from the input stream, or respond with a final status code. The origin server MUST NOT wait for the request body before sending the 100 (Continue) response. If it responds with a final status code, it MAY close the transport connection or it MAY continue to read and discard the rest of the request. It MUST NOT perform the requested method if it returns a final status code.

Currently, spray-can does not do this, and it causes several clients to misbehave. For example, libcurl (and curl) add the Expect: 100-continue header to every outgoing request with a request body. This causes libcurl based apps to pause before sending the body of the request.

The simple, naive solution would be to have spray-can immediately send a 100 Continue response immediately after reading in a request that contains the Expect header mentioned above. The intent of the behavior described above is for servers to fail fast on requests that they know they can't process (for example, ones to an invalid path/route) before the client sends a potentially large request body on. I suspect the simple solution is really the only way to go for a container like spray unless some elegant way of querying an HttpService actor about it's ability to handle a certain path before 'really' processing the request can be done.

sirthias commented 12 years ago

Fixed in the current spray-can 1.0 (milestone) in the spray repository.