kamu-wang 0.03 → 0.04
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/wang.rb +4 -2
- data/wang.gemspec +1 -1
- metadata +1 -1
data/lib/wang.rb
CHANGED
@@ -62,6 +62,7 @@ module WANG
|
|
62
62
|
# [:open_timeout] defines the timeout for connecting in seconds
|
63
63
|
# [:debug] any value passed defines debug mode
|
64
64
|
# [:proxy_address] defines the proxy address to use for all the requests made (host:port)
|
65
|
+
# [:no_keepalive] any value passed will disable keep-alive
|
65
66
|
def initialize args = {}
|
66
67
|
@log = Logger.new(STDOUT)
|
67
68
|
@log.level = args[:debug] ? Logger::DEBUG : Logger::WARN
|
@@ -73,6 +74,7 @@ module WANG
|
|
73
74
|
@read_timeout = args[:read_timeout] || DEFAULT_READ_TIMEOUT
|
74
75
|
@open_timeout = args[:open_timeout] || DEFAULT_OPEN_TIMEOUT
|
75
76
|
@proxy_host, @proxy_port = args[:proxy_address] ? args[:proxy_address].split(':', 2) : [nil, nil]
|
77
|
+
@no_keepalive = args[:no_keepalive]
|
76
78
|
|
77
79
|
@log.debug("Connecting through a proxy: #{@proxy_host}:#{@proxy_port}") if @proxy_host
|
78
80
|
@log.debug("Using #{@read_timeout} as the read timeout and #{@open_timeout} as the open timeout")
|
@@ -173,7 +175,7 @@ module WANG
|
|
173
175
|
body = read_body(headers) if returns_body?(method)
|
174
176
|
@log.debug("WANGJAR: #{@jar.inspect}")
|
175
177
|
|
176
|
-
@socket.close if headers["connection"] =~ /close/
|
178
|
+
@socket.close if headers["connection"] =~ /close/ or @no_keepalive
|
177
179
|
|
178
180
|
@responses << Response.new(method, uri, status, headers)
|
179
181
|
return follow_redirect(headers["location"]) if redirect?(status)
|
@@ -195,7 +197,7 @@ module WANG
|
|
195
197
|
"Accept-Encoding: gzip,deflate,identity",
|
196
198
|
"Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7",
|
197
199
|
"Keep-Alive: 300",
|
198
|
-
"Connection: keep-alive",
|
200
|
+
"Connection: #{@no_keepalive ? "close" : "keep-alive"}",
|
199
201
|
referer.nil? ? "" : "Referer: #{referer}\r\n" # an extra \r\n is needed for the last entry
|
200
202
|
].join("\r\n")
|
201
203
|
end
|
data/wang.gemspec
CHANGED