summaryrefslogtreecommitdiffstats
path: root/lib/puppet/network/http
diff options
context:
space:
mode:
authorMarkus Roberts <Markus@reality.com>2010-07-09 18:06:06 -0700
committerMarkus Roberts <Markus@reality.com>2010-07-09 18:06:06 -0700
commit81e283b28cdd91d259e3b60687aee7ea66e9d05d (patch)
treee3c7b6e4b41cc219f75a3ae7d1294652ead6f268 /lib/puppet/network/http
parente8cf06336b64491a2dd7538a06651e0caaf6a48d (diff)
downloadpuppet-81e283b28cdd91d259e3b60687aee7ea66e9d05d.tar.gz
puppet-81e283b28cdd91d259e3b60687aee7ea66e9d05d.tar.xz
puppet-81e283b28cdd91d259e3b60687aee7ea66e9d05d.zip
Code smell: Line modifiers are preferred to one-line blocks.
* Replaced 6 occurances of (while .*?) *do$ with The do is unneeded in the block header form and causes problems with the block-to-one-line transformation. 3 Examples: The code: while line = f.gets do becomes: while line = f.gets The code: while line = shadow.gets do becomes: while line = shadow.gets The code: while wrapper = zeros.pop do becomes: while wrapper = zeros.pop * Replaced 19 occurances of ((if|unless) .*?) *then$ with The then is unneeded in the block header form and causes problems with the block-to-one-line transformation. 3 Examples: The code: if f = test_files_for(failed).find { |f| failed_trace =~ Regexp.new(f) } then becomes: if f = test_files_for(failed).find { |f| failed_trace =~ Regexp.new(f) } The code: unless defined?(@spec_command) then becomes: unless defined?(@spec_command) The code: if c == ?\n then becomes: if c == ?\n * Replaced 758 occurances of ((?:if|unless|while|until) .*) (.*) end with The one-line form is preferable provided: * The condition is not used to assign a variable * The body line is not already modified * The resulting line is not too long 3 Examples: The code: if Puppet.features.libshadow? has_feature :manages_passwords end becomes: has_feature :manages_passwords if Puppet.features.libshadow? The code: unless (defined?(@current_pool) and @current_pool) @current_pool = process_zpool_data(get_pool_data) end becomes: @current_pool = process_zpool_data(get_pool_data) unless (defined?(@current_pool) and @current_pool) The code: if Puppet[:trace] puts detail.backtrace end becomes: puts detail.backtrace if Puppet[:trace]
Diffstat (limited to 'lib/puppet/network/http')
-rw-r--r--lib/puppet/network/http/api/v1.rb4
-rw-r--r--lib/puppet/network/http/mongrel.rb4
-rw-r--r--lib/puppet/network/http/rack/xmlrpc.rb4
-rw-r--r--lib/puppet/network/http/webrick.rb8
-rw-r--r--lib/puppet/network/http/webrick/rest.rb4
5 files changed, 7 insertions, 17 deletions
diff --git a/lib/puppet/network/http/api/v1.rb b/lib/puppet/network/http/api/v1.rb
index 25e27c486..347da93a6 100644
--- a/lib/puppet/network/http/api/v1.rb
+++ b/lib/puppet/network/http/api/v1.rb
@@ -39,9 +39,7 @@ module Puppet::Network::HTTP::API::V1
end
def indirection_method(http_method, indirection)
- unless METHOD_MAP[http_method]
- raise ArgumentError, "No support for http method #{http_method}"
- end
+ raise ArgumentError, "No support for http method #{http_method}" unless METHOD_MAP[http_method]
unless method = METHOD_MAP[http_method][plurality(indirection)]
raise ArgumentError, "No support for plural #{http_method} operations"
diff --git a/lib/puppet/network/http/mongrel.rb b/lib/puppet/network/http/mongrel.rb
index 8181600e3..88494eea8 100644
--- a/lib/puppet/network/http/mongrel.rb
+++ b/lib/puppet/network/http/mongrel.rb
@@ -40,9 +40,7 @@ class Puppet::Network::HTTP::Mongrel
klass = class_for_protocol(:rest)
@server.register('/', klass.new(:server => @server))
- if @protocols.include?(:xmlrpc) and ! @xmlrpc_handlers.empty?
- setup_xmlrpc_handlers
- end
+ setup_xmlrpc_handlers if @protocols.include?(:xmlrpc) and ! @xmlrpc_handlers.empty?
end
# Use our existing code to provide the xmlrpc backward compatibility.
diff --git a/lib/puppet/network/http/rack/xmlrpc.rb b/lib/puppet/network/http/rack/xmlrpc.rb
index 49eb6fe49..9192b1d48 100644
--- a/lib/puppet/network/http/rack/xmlrpc.rb
+++ b/lib/puppet/network/http/rack/xmlrpc.rb
@@ -18,12 +18,12 @@ class Puppet::Network::HTTP::RackXMLRPC < Puppet::Network::HTTP::RackHttpHandler
def process(request, response)
# errors are sent as text/plain
response['Content-Type'] = 'text/plain'
- if not request.post? then
+ if not request.post?
response.status = 405
response.write 'Method Not Allowed'
return
end
- if request.media_type() != "text/xml" then
+ if request.media_type() != "text/xml"
response.status = 400
response.write 'Bad Request'
return
diff --git a/lib/puppet/network/http/webrick.rb b/lib/puppet/network/http/webrick.rb
index d0533f7ff..66932ad2c 100644
--- a/lib/puppet/network/http/webrick.rb
+++ b/lib/puppet/network/http/webrick.rb
@@ -105,9 +105,7 @@ class Puppet::Network::HTTP::WEBrick
results[:SSLStartImmediately] = true
results[:SSLEnable] = true
- unless Puppet::SSL::Certificate.find(Puppet::SSL::CA_NAME)
- raise Puppet::Error, "Could not find CA certificate"
- end
+ raise Puppet::Error, "Could not find CA certificate" unless Puppet::SSL::Certificate.find(Puppet::SSL::CA_NAME)
results[:SSLCACertificateFile] = Puppet[:localcacert]
results[:SSLVerifyClient] = OpenSSL::SSL::VERIFY_PEER
@@ -125,9 +123,7 @@ class Puppet::Network::HTTP::WEBrick
@server.mount('/', klass, :this_value_is_apparently_necessary_but_unused)
# And then set up xmlrpc, if configured.
- if @protocols.include?(:xmlrpc) and ! @xmlrpc_handlers.empty?
- @server.mount("/RPC2", xmlrpc_servlet)
- end
+ @server.mount("/RPC2", xmlrpc_servlet) if @protocols.include?(:xmlrpc) and ! @xmlrpc_handlers.empty?
end
# Create our xmlrpc servlet, which provides backward compatibility.
diff --git a/lib/puppet/network/http/webrick/rest.rb b/lib/puppet/network/http/webrick/rest.rb
index 9bfd0ce6a..9a8bf0a83 100644
--- a/lib/puppet/network/http/webrick/rest.rb
+++ b/lib/puppet/network/http/webrick/rest.rb
@@ -52,9 +52,7 @@ class Puppet::Network::HTTP::WEBrickREST < WEBrick::HTTPServlet::AbstractServlet
response.status = status
if status >= 200 and status != 304
response.body = result
- if result.is_a?(File)
- response["content-length"] = result.stat.size
- end
+ response["content-length"] = result.stat.size if result.is_a?(File)
end
response.reason_phrase = result if status < 200 or status >= 300
end