Sha256: c1d1d02534279902446017e79b9d66fe70207481eebef356997a4d63d63035be

Contents?: true

Size: 641 Bytes

Versions: 5

Compression:

Stored size: 641 Bytes

Contents

require 'webmachine/constants'

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

    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
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
webmachine-1.6.0 lib/webmachine/header_negotiation.rb
webmachine-1.5.0 lib/webmachine/header_negotiation.rb
webmachine-1.4.0 lib/webmachine/header_negotiation.rb
webmachine-1.3.1 lib/webmachine/header_negotiation.rb
webmachine-1.3.0 lib/webmachine/header_negotiation.rb