Class: EventMachine::HttpResponseHeader

Inherits:
Hash
  • Object
show all
Defined in:
lib/em-http/http_header.rb

Overview

A simple hash is returned for each request made by HttpClient with the headers that were given by the server for that request.

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#http_reasonObject

The reason returned in the http response (“OK”,“File not found”,etc.)



6
7
8
# File 'lib/em-http/http_header.rb', line 6

def http_reason
  @http_reason
end

#http_statusObject

The status code (as a string!)



12
13
14
# File 'lib/em-http/http_header.rb', line 12

def http_status
  @http_status
end

#http_versionObject

The HTTP version returned.



9
10
11
# File 'lib/em-http/http_header.rb', line 9

def http_version
  @http_version
end

Instance Method Details

#[](key) ⇒ Object



56
57
58
# File 'lib/em-http/http_header.rb', line 56

def [](key)
  super(key) || super(key.upcase.gsub('-','_'))
end

#chunked_encoding?Boolean

Is the transfer encoding chunked?

Returns:

  • (Boolean)


40
41
42
# File 'lib/em-http/http_header.rb', line 40

def chunked_encoding?
  /chunked/i === self[HttpClient::TRANSFER_ENCODING]
end

#compressed?Boolean

Returns:

  • (Boolean)


48
49
50
# File 'lib/em-http/http_header.rb', line 48

def compressed?
  /gzip|compressed|deflate/i === self[HttpClient::CONTENT_ENCODING]
end

#content_lengthObject

Length of content as an integer, or nil if chunked/unspecified



29
30
31
32
# File 'lib/em-http/http_header.rb', line 29

def content_length
  @content_length ||= ((s = self[HttpClient::CONTENT_LENGTH]) &&
                       (s =~ /^(\d+)$/)) ? $1.to_i : nil
end

Cookie header from the server



35
36
37
# File 'lib/em-http/http_header.rb', line 35

def cookie
  self[HttpClient::SET_COOKIE]
end

#etagObject

E-Tag



15
16
17
# File 'lib/em-http/http_header.rb', line 15

def etag
  self[HttpClient::ETAG]
end

#keepalive?Boolean

Returns:

  • (Boolean)


44
45
46
# File 'lib/em-http/http_header.rb', line 44

def keepalive?
  /keep-alive/i === self[HttpClient::KEEP_ALIVE]
end

#last_modifiedObject



19
20
21
# File 'lib/em-http/http_header.rb', line 19

def last_modified
  self[HttpClient::LAST_MODIFIED]
end

#locationObject



52
53
54
# File 'lib/em-http/http_header.rb', line 52

def location
  self[HttpClient::LOCATION]
end

#statusObject

HTTP response status as an integer



24
25
26
# File 'lib/em-http/http_header.rb', line 24

def status
  Integer(http_status) rescue 0
end