Module: HTTPkit::Support::Message

Included in:
Request, Response
Defined in:
lib/httpkit/support/message.rb

Constant Summary collapse

TRANSFER_ENCODING =
'Transfer-Encoding'.freeze
CHUNKED =
'chunked'.freeze
CONTENT_LENGTH =
'Content-Length'.freeze

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.build(parser) ⇒ Object


44
45
46
47
48
# File 'lib/httpkit/support/message.rb', line 44

def self.build(parser)
  message = build_message(parser)
  message.close if !message.body_included? || !message.body_present?
  message
end

Instance Method Details

#body_headersObject


30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/httpkit/support/message.rb', line 30

def body_headers
  length, encoding = nil, nil

  if body_present?
    if body.length_known?
      length = body.length.to_i
    else
      encoding = CHUNKED
    end
  end

  { CONTENT_LENGTH => length, TRANSFER_ENCODING => encoding }
end

#closeObject


22
23
24
# File 'lib/httpkit/support/message.rb', line 22

def close
  body.closed.fulfill
end

#closed(&block) ⇒ Object


18
19
20
# File 'lib/httpkit/support/message.rb', line 18

def closed(&block)
  body.closed.then(&block)
end

#closed!Object


14
15
16
# File 'lib/httpkit/support/message.rb', line 14

def closed!
  body.closed.sync
end

#closed?Boolean


10
11
12
# File 'lib/httpkit/support/message.rb', line 10

def closed?
  !body.closed.pending?
end

#reject_closed(reason) ⇒ Object


26
27
28
# File 'lib/httpkit/support/message.rb', line 26

def reject_closed(reason)
  body.closed.reject(reason)
end