-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(PUP-10730) Separate abstract response and net http adapter
Move behavior specific to Net::HTTPResponse into an adapter, and leave the common behaviors in the abstract Puppet::HTTP::Response class. It also makes it possible to create a response in tests given just the URL, code and status.
- Loading branch information
1 parent
06b7b17
commit e0dab29
Showing
8 changed files
with
78 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
# Adapts Net::HTTPResponse to Puppet::HTTP::Response | ||
# | ||
# @api public | ||
class Puppet::HTTP::ResponseNetHTTP < Puppet::HTTP::Response | ||
|
||
# Create a response associated with the URL. | ||
# | ||
# @param [URI] url | ||
# @param [Net::HTTPResponse] nethttp The response | ||
def initialize(url, nethttp) | ||
super(url, nethttp.code.to_i, nethttp.message) | ||
|
||
@nethttp = nethttp | ||
end | ||
|
||
# (see Puppet::HTTP::Response#body) | ||
def body | ||
@nethttp.body | ||
end | ||
|
||
# (see Puppet::HTTP::Response#read_body) | ||
def read_body(&block) | ||
raise ArgumentError, "A block is required" unless block_given? | ||
|
||
@nethttp.read_body(&block) | ||
end | ||
|
||
# (see Puppet::HTTP::Response#success?) | ||
def success? | ||
@nethttp.is_a?(Net::HTTPSuccess) | ||
end | ||
|
||
# (see Puppet::HTTP::Response#[]) | ||
def [](name) | ||
@nethttp[name] | ||
end | ||
|
||
# (see Puppet::HTTP::Response#each_header) | ||
def each_header(&block) | ||
@nethttp.each_header(&block) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters