kamu-wang 0.03 → 0.04

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. data/lib/wang.rb +4 -2
  2. data/wang.gemspec +1 -1
  3. 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
@@ -1,7 +1,7 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.platform = Gem::Platform::RUBY
3
3
  s.name = 'wang'
4
- s.version = "0.03"
4
+ s.version = "0.04"
5
5
  s.summary = "Web Access with No Grief."
6
6
  s.authors = ["Kamu", "Joux3"]
7
7
  s.email = "mr.kamu@gmail.com"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kamu-wang
3
3
  version: !ruby/object:Gem::Version
4
- version: "0.03"
4
+ version: "0.04"
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kamu