Class: EventMachine::AblyHttpRequest::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”)



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

def http_reason
  @http_reason
end

#http_statusObject

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



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

def http_status
  @http_status
end

#http_versionObject

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



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

def http_version
  @http_version
end

#rawObject

Raw headers



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

def raw
  @raw
end

Instance Method Details

#[](key) ⇒ Object



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

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

#chunked_encoding?Boolean

Is the transfer encoding chunked?

Returns:

  • (Boolean)


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

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

#client_error?Boolean

Returns:

  • (Boolean)


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

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

#compressed?Boolean

Returns:

  • (Boolean)


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

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

#content_lengthObject

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



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

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

Cookie header from the server



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

def cookie
  self[HttpClient::SET_COOKIE]
end

#etagObject

E-Tag



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

def etag
  self[HttpClient::ETAG]
end

#informational?Boolean

Returns:

  • (Boolean)


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

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

#keepalive?Boolean

Returns:

  • (Boolean)


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

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

#last_modifiedObject



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

def last_modified
  self[HttpClient::LAST_MODIFIED]
end

#locationObject



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

def location
  self[HttpClient::LOCATION]
end

#redirection?Boolean

Returns:

  • (Boolean)


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

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

#server_error?Boolean

Returns:

  • (Boolean)


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

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

#statusObject

HTTP response status



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

def status
  Integer(http_status) rescue 0
end

#successful?Boolean

Returns:

  • (Boolean)


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

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