Skip to content
Browse files

Explain the proper way of sending parameters

For GET, HEAD and other requests that do not allow a body you send the
query params in the request line, but in POST and other requests that do
you send such parameters in the body.

Now this difference is explained better in the top-level documentation.

Fixes #35
  • Loading branch information...
1 parent c0812e2 commit 24c70e0d653e0f072ef3bbab48baa230bb1eafe1 @drbrain committed
Showing with 25 additions and 8 deletions.
  1. +25 −8 lib/net/http/persistent.rb
View
33 lib/net/http/persistent.rb
@@ -37,6 +37,11 @@
# # perform a GET
# response = http.request uri
#
+# # or
+#
+# get = Net::HTTP::Get.new uri.request_uri
+# response = http.request get
+#
# # create a POST
# post_uri = uri + 'create'
# post = Net::HTTP::Post.new post_uri.path
@@ -45,6 +50,10 @@
# # perform the POST, the URI is always required
# response http.request post_uri, post
#
+# Note that for GET, HEAD and other requests that do not have a body you want
+# to use URI#request_uri not URI#path. The request_uri contains the query
+# params which are sent in the body for other requests.
+#
# == SSL
#
# SSL connections are automatically created depending upon the scheme of the
@@ -950,14 +959,7 @@ def request uri, req = nil, &block
Errno::ECONNABORTED, Errno::ECONNRESET, Errno::EPIPE,
Errno::EINVAL, OpenSSL::SSL::SSLError => e
- if retried or not can_retry? req
- due_to = "(due to #{e.message} - #{e.class})"
- message = error_message connection
-
- finish connection
-
- raise Error, "too many connection resets #{due_to} #{message}"
- end
+ request_failed e, req, connection if retried or not can_retry? req
reset connection
@@ -973,6 +975,21 @@ def request uri, req = nil, &block
end
##
+ # Raises an Error for +exception+ which resulted from attempting the request
+ # +req+ on the +connection+.
+ #
+ # Finishes the +connection+.
+
+ def request_failed exception, req, connection # :nodoc:
+ due_to = "(due to #{exception.message} - #{exception.class})"
+ message = error_message connection
+
+ finish connection
+
+ raise Error, "too many connection resets #{due_to} #{message}"
+ end
+
+ ##
# Shuts down all connections for +thread+.
#
# Uses the current thread by default.

0 comments on commit 24c70e0

Please sign in to comment.
Something went wrong with that request. Please try again.