Module: Webmachine::HeaderNegotiation

Included in:
Webmachine, Decision::Helpers
Defined in:
lib/webmachine/header_negotiation.rb

Instance Method Summary collapse

Instance Method Details

#ensure_content_length(res) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/webmachine/header_negotiation.rb', line 11

def ensure_content_length(res)
  body = res.body
  case
  when res.headers[TRANSFER_ENCODING]
    return
  when [204, 205, 304].include?(res.code)
    res.headers.delete CONTENT_LENGTH
  when body != nil
    res.headers[CONTENT_LENGTH] = body.respond_to?(:bytesize) ? body.bytesize.to_s : body.length.to_s
  else
    res.headers[CONTENT_LENGTH] = '0'
  end
end

#ensure_date_header(res) ⇒ Object



5
6
7
8
9
# File 'lib/webmachine/header_negotiation.rb', line 5

def ensure_date_header(res)
  if (200..499).include?(res.code)
    res.headers[DATE] ||= Time.now.httpdate
  end
end