-
-
Notifications
You must be signed in to change notification settings - Fork 88
Disable body reading on head requests #95
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 5 commits
fce2fe0
96c6679
cd733dd
673ab04
9794e6f
f12ace7
72ddf9f
9df953e
189bf36
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -1,11 +1,11 @@ | ||||||
package requests | ||||||
|
||||||
import requests.Requester.methodField | ||||||
|
||||||
import java.io.{ByteArrayInputStream, ByteArrayOutputStream, OutputStream} | ||||||
import java.net.{HttpCookie, HttpURLConnection, InetSocketAddress} | ||||||
import java.util.zip.{GZIPInputStream, InflaterInputStream} | ||||||
|
||||||
import javax.net.ssl._ | ||||||
|
||||||
import collection.JavaConverters._ | ||||||
import scala.collection.mutable | ||||||
|
||||||
|
@@ -34,6 +34,8 @@ trait BaseSession{ | |||||
lazy val options = Requester("OPTIONS", this) | ||||||
// unofficial | ||||||
lazy val patch = Requester("PATCH", this) | ||||||
|
||||||
def send(method: String) = Requester(method, this) | ||||||
} | ||||||
|
||||||
object BaseSession{ | ||||||
|
@@ -281,7 +283,6 @@ case class Requester(verb: String, | |||||
|
||||||
val deGzip = autoDecompress && headerFields.get("content-encoding").toSeq.flatten.exists(_.contains("gzip")) | ||||||
val deDeflate = autoDecompress && headerFields.get("content-encoding").toSeq.flatten.exists(_.contains("deflate")) | ||||||
|
||||||
def persistCookies() = { | ||||||
if (sess.persistCookies) { | ||||||
headerFields | ||||||
|
@@ -331,7 +332,11 @@ case class Requester(verb: String, | |||||
else connection.getErrorStream | ||||||
|
||||||
def processWrappedStream[V](f: java.io.InputStream => V): V = { | ||||||
if (stream != null) { | ||||||
// The HEAD method is identical to GET except that the server | ||||||
// MUST NOT return a message-body in the response. | ||||||
// https://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html section 9.4 | ||||||
if (verb.toLowerCase == "head") f(new ByteArrayInputStream(Array())) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The HTTP verbs are case-sensitive. Probably you need to check for
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @lolgab updated as per your suggestion |
||||||
else if (stream != null) { | ||||||
try f( | ||||||
if (deGzip) new GZIPInputStream(stream) | ||||||
else if (deDeflate) new InflaterInputStream(stream) | ||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package requests | ||
|
||
import utest._ | ||
import ujson._ | ||
|
||
object Scala2RequestTests extends TestSuite{ | ||
val tests = Tests{ | ||
test("send"){ | ||
requests.send("get")("https://httpbin.org/get?hello=world&foo=baz") | ||
|
||
// This doesn't compile right in Scala3 for some reason | ||
val res1 = requests.send("put")( | ||
"https://httpbin.org/put", | ||
data = Map("hello" -> "world", "foo" -> "baz"), | ||
chunkedUpload = true | ||
).text | ||
|
||
assert(read(res1).obj("form") == Obj("foo" -> "baz", "hello" -> "world")) | ||
} | ||
} | ||
} |
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this a spurious change?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah, will remove