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 (string - e.g. “OK”)



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

def http_reason
  @http_reason
end

#http_statusObject

The status code (integer - e.g. 200)



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

def http_status
  @http_status
end

#http_versionObject

The HTTP version returned (string - e.g. “1.1”)



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

def http_version
  @http_version
end

#rawObject

Raw headers



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

def raw
  @raw
end

Instance Method Details

#[](key) ⇒ Object



59
60
61
# File 'lib/em-http/http_header.rb', line 59

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

#chunked_encoding?Boolean

Is the transfer encoding chunked?

Returns:

  • (Boolean)


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

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

#client_error?Boolean

Returns:

  • (Boolean)


75
76
77
# File 'lib/em-http/http_header.rb', line 75

def client_error?
  400 <= status && 500 > status
end

#compressed?Boolean

Returns:

  • (Boolean)


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

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

#content_lengthObject

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



32
33
34
35
# File 'lib/em-http/http_header.rb', line 32

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

Cookie header from the server



38
39
40
# File 'lib/em-http/http_header.rb', line 38

def cookie
  self[HttpClient::SET_COOKIE]
end

#etagObject

E-Tag



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

def etag
  self[HttpClient::ETAG]
end

#informational?Boolean

Returns:

  • (Boolean)


63
64
65
# File 'lib/em-http/http_header.rb', line 63

def informational?
  100 <= status && 200 > status
end

#keepalive?Boolean

Returns:

  • (Boolean)


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

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

#last_modifiedObject



22
23
24
# File 'lib/em-http/http_header.rb', line 22

def last_modified
  self[HttpClient::LAST_MODIFIED]
end

#locationObject



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

def location
  self[HttpClient::LOCATION]
end

#redirection?Boolean

Returns:

  • (Boolean)


71
72
73
# File 'lib/em-http/http_header.rb', line 71

def redirection?
  300 <= status && 400 > status
end

#server_error?Boolean

Returns:

  • (Boolean)


79
80
81
# File 'lib/em-http/http_header.rb', line 79

def server_error?
  500 <= status && 600 > status
end

#statusObject

HTTP response status



27
28
29
# File 'lib/em-http/http_header.rb', line 27

def status
  Integer(http_status) rescue 0
end

#successful?Boolean

Returns:

  • (Boolean)


67
68
69
# File 'lib/em-http/http_header.rb', line 67

def successful?
  200 <= status && 300 > status
end