about summary refs log tree commit homepage
path: root/lib
diff options
context:
space:
mode:
authorEric Wong <bofh@yhbt.net>2020-03-19 02:28:23 +0000
committerEric Wong <bofh@yhbt.net>2020-03-19 08:22:27 +0000
commit193b968013462c2966d7175a0f509625e98830ea (patch)
tree816a43bdbd28565167b8a548bef49ca0083275e6 /lib
parentb6c62e1b80ae1282ef99b8b641486446aa438e31 (diff)
downloadunicorn-193b968013462c2966d7175a0f509625e98830ea.tar.gz
We need to favor "Transfer-Encoding: chunked" over
"Content-Length" in the request header if they both exist.
Furthermore, we now reject redundant chunking and cases where
"chunked" is not the final encoding.

We currently do not and have no plans to decode "gzip",
"deflate", or "compress" encoding as described by RFC 7230.
That's a job more appropriate for middleware, anyways.

cf. https://tools.ietf.org/html/rfc7230
    https://www.rfc-editor.org/errata_search.php?rfc=7230
Diffstat (limited to 'lib')
-rw-r--r--lib/unicorn/http_request.rb11
1 files changed, 11 insertions, 0 deletions
diff --git a/lib/unicorn/http_request.rb b/lib/unicorn/http_request.rb
index bcc1f2d..6ca4592 100644
--- a/lib/unicorn/http_request.rb
+++ b/lib/unicorn/http_request.rb
@@ -188,4 +188,15 @@ class Unicorn::HttpParser
       HTTP_RESPONSE_START.each { |c| socket.write(c) }
     end
   end
+
+  # called by ext/unicorn_http/unicorn_http.rl via rb_funcall
+  def self.is_chunked?(v) # :nodoc:
+    vals = v.split(/[ \t]*,[ \t]*/).map!(&:downcase)
+    if vals.pop == 'chunked'.freeze
+      return true unless vals.include?('chunked'.freeze)
+      raise Unicorn::HttpParserError, 'double chunked', []
+    end
+    return false unless vals.include?('chunked'.freeze)
+    raise Unicorn::HttpParserError, 'chunked not last', []
+  end
 end