@@ -3,9 +3,7 @@ package requests
33import java .io .{ByteArrayInputStream , ByteArrayOutputStream , OutputStream }
44import java .net .{HttpCookie , HttpURLConnection , InetSocketAddress }
55import java .util .zip .{GZIPInputStream , InflaterInputStream }
6-
76import javax .net .ssl ._
8-
97import collection .JavaConverters ._
108import scala .collection .mutable
119
@@ -283,7 +281,6 @@ case class Requester(verb: String,
283281
284282 val deGzip = autoDecompress && headerFields.get(" content-encoding" ).toSeq.flatten.exists(_.contains(" gzip" ))
285283 val deDeflate = autoDecompress && headerFields.get(" content-encoding" ).toSeq.flatten.exists(_.contains(" deflate" ))
286-
287284 def persistCookies () = {
288285 if (sess.persistCookies) {
289286 headerFields
@@ -333,7 +330,11 @@ case class Requester(verb: String,
333330 else connection.getErrorStream
334331
335332 def processWrappedStream [V ](f : java.io.InputStream => V ): V = {
336- if (stream != null ) {
333+ // The HEAD method is identical to GET except that the server
334+ // MUST NOT return a message-body in the response.
335+ // https://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html section 9.4
336+ if (verb == " HEAD" ) f(new ByteArrayInputStream (Array ()))
337+ else if (stream != null ) {
337338 try f(
338339 if (deGzip) new GZIPInputStream (stream)
339340 else if (deDeflate) new InflaterInputStream (stream)
0 commit comments