Skip to content

Commit

Permalink
Added http_status to Network::Mixin::HTTP and updated documentation.
Browse files Browse the repository at this point in the history
  • Loading branch information
postmodern committed Apr 24, 2011
1 parent 579d718 commit d68f8bf
Showing 1 changed file with 104 additions and 69 deletions.
173 changes: 104 additions & 69 deletions lib/ronin/network/mixins/http.rb
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,110 @@ def http_request(options={},&block)
return Net.http_request(options,&block)
end

#
# Returns the Status Code of the Response.
#
# @param [Hash] options
# Additional options.
#
# @option options [Symbol, String] :method (:head)
# The method to use for the request.
#
# @return [Integer]
# The HTTP Response Status.
#
# @see #http_request
#
# @since 1.1.0
#
def http_status(options={})
options = http_merge_options(options)

if (result = Net.http_status(options))
print_debug "HTTP #{result} #{http_options_to_s(options)}"
end

return result
end

#
# Checks if the response has an HTTP OK status code.
#
# @param [Hash] options
# Additional options.
#
# @option options [Symbol, String] :method (:head)
# The method to use for the request.
#
# @return [Boolean]
# Specifies wether the response had an HTTP OK status code or not.
#
# @see #http_status
#
# @since 1.1.0
#
def http_ok?(options={})
options = http_merge_options(options)

if (result = Net.http_ok?(options))
print_debug "HTTP 200 OK #{http_options_to_s(options)}"
end

return result
end

#
# Sends a HTTP Head request and returns the HTTP Server header.
#
# @param [Hash] options
# Additional options.
#
# @option options [Symbol, String] :method (:head)
# The method to use for the request.
#
# @return [String]
# The HTTP `Server` header.
#
# @see #http_request
#
# @since 1.1.0
#
def http_server(options={})
options = http_merge_options(options)

if (result = Net.http_server(options))
print_debug "HTTP Server: #{result}"
end

return result
end

#
# Sends an HTTP Head request and returns the HTTP X-Powered-By header.
#
# @param [Hash] options
# Additional options.
#
# @option options [Symbol, String] :method (:get)
# The method to use for the request.
#
# @return [String]
# The HTTP `X-Powered-By` header.
#
# @see #http_request
#
# @since 1.1.0
#
def http_powered_by(options={})
options = http_merge_options(options)

if (result = Net.http_powered_by(options))
print_debug "HTTP X-Powered-By: #{result}"
end

return result
end

#
# Performs an HTTP Copy request.
#
Expand Down Expand Up @@ -275,75 +379,6 @@ def http_head(options={},&block)
return Net.http_head(options,&block)
end

#
# Checks if the response has an HTTP OK status code.
#
# @param [Hash] options
# Additional options.
#
# @return [Boolean]
# Specifies wether the response had an HTTP OK status code or not.
#
# @see #http_request
#
# @since 1.1.0
#
def http_ok?(options={})
options = http_merge_options(options)

if (result = Net.http_ok?(options))
print_debug "HTTP 200 OK #{http_options_to_s(options)}"
end

return result
end

#
# Sends a HTTP Head request and returns the HTTP Server header.
#
# @param [Hash] options
# Additional options.
#
# @return [String]
# The HTTP `Server` header.
#
# @see #http_request
#
# @since 1.1.0
#
def http_server(options={})
options = http_merge_options(options)

if (result = Net.http_server(options))
print_debug "HTTP Server: #{result}"
end

return result
end

#
# Sends an HTTP Head request and returns the HTTP X-Powered-By header.
#
# @param [Hash] options
# Additional options.
#
# @return [String]
# The HTTP `X-Powered-By` header.
#
# @see #http_request
#
# @since 1.1.0
#
def http_powered_by(options={})
options = http_merge_options(options)

if (result = Net.http_powered_by(options))
print_debug "HTTP X-Powered-By: #{result}"
end

return result
end

#
# Performs an HTTP Lock request.
#
Expand Down

0 comments on commit d68f8bf

Please sign in to comment.