Class: Puppet::HTTP::Response

Inherits:
Object
  • Object
show all
Defined in:
lib/puppet/http/response.rb

Overview

Represents the response returned from the server from an HTTP request.

Direct Known Subclasses

ResponseNetHTTP

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(url, code, reason) ⇒ Response

Create a response associated with the URL.

Parameters:

  • url (URI)
  • HTTP (Integer)

    status

  • HTTP (String)

    reason



16
17
18
19
20
# File 'lib/puppet/http/response.rb', line 16

def initialize(url, code, reason)
  @url = url
  @code = code
  @reason = reason
end

Instance Attribute Details

#urlURI (readonly)

Returns the response url.

Returns:

  • (URI)

    the response url



9
10
11
# File 'lib/puppet/http/response.rb', line 9

def url
  @url
end

Instance Method Details

#[](name) ⇒ String

Get a header case-insensitively.

Parameters:

  • name (String)

    The header name

Returns:

  • (String)

    The header value

Raises:

  • (NotImplementedError)


79
80
81
# File 'lib/puppet/http/response.rb', line 79

def [](name)
  raise NotImplementedError
end

#bodyString

Returns the entire response body. Can be used instead of

`Puppet::HTTP::Response.read_body`, but both methods cannot be used for the
same response.

Returns:

  • (String)

    Response body for the request

Raises:

  • (NotImplementedError)


47
48
49
# File 'lib/puppet/http/response.rb', line 47

def body
  raise NotImplementedError
end

#codeInteger

Return the response code.

Returns:

  • (Integer)

    Response code for the request



27
28
29
# File 'lib/puppet/http/response.rb', line 27

def code
  @code
end

#drainObject

Ensure the response body is fully read so that the server is not blocked waiting for us to read data from the socket. Also if the caller streamed the response, but didn’t read the data, we need a way to drain the socket before adding the connection back to the connection pool, otherwise the unread response data would “leak” into the next HTTP request/response.



100
101
102
103
# File 'lib/puppet/http/response.rb', line 100

def drain
  body
  true
end

#each_header {|header, header| ... } ⇒ Object

Yield each header name and value. Returns an enumerator if no block is given.

Yield Parameters:

  • header (String)

    name

  • header (String)

    value

Raises:

  • (NotImplementedError)


89
90
91
# File 'lib/puppet/http/response.rb', line 89

def each_header(&block)
  raise NotImplementedError
end

#read_body {|String| ... } ⇒ Object

Streams the response body to the caller in chunks. Can be used instead of

`Puppet::HTTP::Response.body`, but both methods cannot be used for the same
response.

Yields:

  • (String)

    Streams the response body in chunks

Raises:

  • (ArgumentError)

    raise if a block is not given



60
61
62
# File 'lib/puppet/http/response.rb', line 60

def read_body(&block)
  raise NotImplementedError
end

#reasonString

Return the response message.

Returns:

  • (String)

    Response message for the request



36
37
38
# File 'lib/puppet/http/response.rb', line 36

def reason
  @reason
end

#success?Boolean

Check if the request received a response of success (HTTP 2xx).

Returns:

  • (Boolean)

    Returns true if the response indicates success



69
70
71
# File 'lib/puppet/http/response.rb', line 69

def success?
  200 <= @code && @code < 300
end