Sha256: 7a17f7130200c7f357298df6c6de406b4b0ed60bc1ce940a71bacb02b85a2453
Contents?: true
Size: 1.13 KB
Versions: 1
Compression:
Stored size: 1.13 KB
Contents
# encoding: utf-8 module Hatetepe class Serializer module Encoding TRANSFER_ENCODING = 'Transfer-Encoding'.freeze CHUNKED = 'chunked'.freeze CRLF = "\r\n".freeze CONTENT_LENGTH = 'Content-Length'.freeze def setup_body if body.closed.pending? setup_chunked_encoding setup_chunked_streaming else setup_identity_encoding end end def setup_chunked_encoding headers.delete(CONTENT_LENGTH) headers[TRANSFER_ENCODING] = CHUNKED end def setup_chunked_streaming body.closed.on_progress { |chunk| write_chunk(chunk) } body.closed.then { |_| write_chunk!('') } end def setup_identity_encoding headers.delete(TRANSFER_ENCODING) headers[CONTENT_LENGTH] = body.to_s.bytesize end def write_body if headers.key?(CONTENT_LENGTH) write(body.to_s) end end def write_chunk(chunk) write_chunk!(chunk) unless chunk.empty? end def write_chunk!(chunk) write(chunk.bytesize, CRLF, chunk, CRLF) end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
hatetepe-0.6.0.pre.1 | lib/hatetepe/serializer/encoding.rb |