From: "NARUSE, Yui" Date: 2011-07-24T03:09:33+09:00 Subject: [ruby-core:38426] Re: Proposal to merge net2-http for Ruby 1.9.4 (2011/07/23 8:05), Clifford Heath wrote: > On 23/07/2011, at 1:56 AM, Tanaka Akira wrote: >> I guess HTTP POST is not trivial to make an API which is polymorphic to IO. > > In general, that's true. > >> For example, the request data length is required for Content-Length before >> sending the data. > > You don't have to send Content-Length, but you can't Keep-Alive unless you > do (unless you chunk each piece of Content as you discover its length, which > is possible as long as the server is HTTP/1.1 not 1.0). On request, it can't use closing the connection. RFC 1945 (HTTP/1.0) says: --- 7.2.2 Length When an Entity-Body is included with a message, the length of that body may be determined in one of two ways. If a Content-Length header field is present, its value in bytes represents the length of the Entity-Body. Otherwise, the body length is determined by the closing of the connection by the server. Closing the connection cannot be used to indicate the end of a request body, since it leaves no possibility for the server to send back a response. Therefore, HTTP/1.0 requests containing an entity body must include a valid Content-Length header field. If a request contains an entity body and Content-Length is not specified, and the server does not recognize or cannot calculate the length from other fields, then the server should send a 400 (bad request) response. --- > So yes, it's complicated. Sometimes wholesale replacement (and providing a > fallback option) is a better strategy than stepwise refinement. We like providing new but easier method to introduce a better strategy. Anyway, akr's point is not about current implementation. It is wycats' new idea that "Making HTTP similar to IO". -- NARUSE, Yui