Browse files

Ignore incoming Content-Length header when chunking is on

From RFC 2616, section 4.4:

   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
     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.
  • Loading branch information...
1 parent 7576ee1 commit 1728e3f964b1b7146c779efaab791a93d034c7f8 @hanshuebner hanshuebner committed Aug 18, 2013
Showing with 2 additions and 4 deletions.
  1. +2 −4 request.lisp
View
6 request.lisp
@@ -141,17 +141,15 @@ TEXTP is true, the body is assumed to be of content type `text' and
will be returned as a string. Otherwise an array of octets \(or NIL
for an empty body) is returned. Returns the optional `trailer' HTTP
headers of the chunked stream \(if any) as a second value."
- (let ((content-length (when-let (value (header-value :content-length headers))
+ (let ((content-length (when-let (value (and (not (header-value :transfer-encoding headers)) ;; see RFC 2616, section 4.4, 3.
+ (header-value :content-length headers)))
(parse-integer value)))
(element-type (if textp
#+:lispworks 'lw:simple-char #-:lispworks 'character
'octet))
(chunkedp (chunked-stream-input-chunking-p (flexi-stream-stream stream))))
(values (cond ((eql content-length 0) nil)
(content-length
- (when chunkedp
- ;; see RFC 2616, section 4.4
- (syntax-error "Got Content-Length header although input chunking is on."))
(setf (flexi-stream-element-type stream) 'octet)
(let ((result (make-array content-length :element-type 'octet)))
#+:clisp

0 comments on commit 1728e3f

Please sign in to comment.