http_spew 0.6.0 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: adb45872da4a40e1048b41a9e67d770cf36b8492
4
- data.tar.gz: 1529513d35f7690108de8fb47e2762222921211a
3
+ metadata.gz: 6f78a87db667171d544603aa12a83475dab20545
4
+ data.tar.gz: 5f487539a9d355cbc5a979cab70ac4b6788253ed
5
5
  SHA512:
6
- metadata.gz: 15d146b1507a22952149368040593afa81b267c9df596a1ba080391cd66917890fe0472d3580644b6111bf3a163c4e5fd8194b0967eb5c92f200f96a12671b69
7
- data.tar.gz: 8cccbb603644241181634209d8acc42f8b49001e03af46910b41303a12b0b44d70a1e6aee9fa0afbfde644789cd31980236722f098cf3f4b1d7e65a6ceb0cc1f
6
+ metadata.gz: 64a5f0b76fa4d70ffeef6de7120c51677a503bba55972d7063ded10532453bb3c8838cee0445c86da0f5f067a7977a8fd026a31bc399b0bde7c60811c0d33c2c
7
+ data.tar.gz: e22a30b09ab4b87c395084395da3ff477823cf5e28caf048e77ccd56d86692c3cde5c22629c18751662df2084fea6cfdd3fc3752d5a29b9f0ccb0837163e711a
@@ -3,5 +3,4 @@ cgit_url: https://bogomips.org/http_spew.git
3
3
  git_url: git://bogomips.org/http_spew.git
4
4
  rdoc_url: https://bogomips.org/http_spew/
5
5
  ml_url: https://bogomips.org/http_spew-public/
6
- private_email: kcar@bogomips.org
7
6
  public_email: http_spew-public@bogomips.org
@@ -1,7 +1,7 @@
1
1
  #!/bin/sh
2
2
 
3
3
  GVF=GIT-VERSION-FILE
4
- DEF_VER=v0.6.0
4
+ DEF_VER=v0.7.0
5
5
 
6
6
  LF='
7
7
  '
@@ -1,23 +1,20 @@
1
- ENV["VERSION"] or abort "VERSION= must be specified"
2
- manifest = File.readlines('.manifest').map! { |x| x.chomp! }
3
- require 'olddoc'
4
- extend Olddoc::Gemspec
5
- name, summary, title = readme_metadata
1
+ manifest = File.exist?('.manifest') ?
2
+ IO.readlines('.manifest').map!(&:chomp!) : `git ls-files`.split("\n")
6
3
 
7
4
  Gem::Specification.new do |s|
8
5
  s.name = %q{http_spew}
9
- s.version = ENV["VERSION"].dup
10
- s.authors = ["kcar hackers"]
11
- s.description = readme_description
12
- s.email = %q{kcar@bogomips.org}
13
- s.extra_rdoc_files = extra_rdoc_files(manifest)
6
+ s.version = (ENV['VERSION'] || '0.7.0').dup
7
+ s.authors = ["http_spew hackers"]
8
+ s.description = File.read('README').split("\n\n")[1]
9
+ s.email = %q{http_spew-public@bogomips.org}
10
+ s.extra_rdoc_files = IO.readlines('.document').map!(&:chomp!).keep_if do |f|
11
+ File.exist?(f)
12
+ end
14
13
  s.files = manifest
15
- s.homepage = Olddoc.config['rdoc_url']
16
- s.summary = summary
14
+ s.homepage = 'https://bogomips.org/http_spew/'
15
+ s.summary = 'HTTP Spew - LAN-only HTTP spam^H^H^H^Hclient for Ruby'
17
16
  s.test_files = Dir["test/test_*.rb"]
18
17
  s.add_dependency(%q<kcar>, [ "~> 0.3", ">= 0.3.1"])
19
- s.add_dependency(%q<kgio>, "~> 2.6")
20
- s.add_development_dependency(%q<olddoc>, "~> 1.0")
21
- s.required_ruby_version = '>= 2.1'
18
+ s.required_ruby_version = '>= 2.3'
22
19
  s.licenses = %w(GPL-2.0+)
23
20
  end
@@ -1,5 +1,5 @@
1
1
  # -*- encoding: binary -*-
2
- require "kgio"
2
+ require "io/wait"
3
3
  require "kcar"
4
4
 
5
5
  module HTTP_Spew
@@ -3,17 +3,28 @@
3
3
  # This is a OS-level pipe that overrides IO#read to provide
4
4
  # IO#readpartial-like semantics while remaining Rack::Lint-compatible
5
5
  # for EOF, meaning we return nil on EOF instead of raising EOFError.
6
- class HTTP_Spew::ChunkyPipe < Kgio::Pipe
6
+ class HTTP_Spew::ChunkyPipe < IO
7
7
 
8
8
  # other threads may force an error to be raised in the +read+
9
9
  # method
10
10
  attr_accessor :error
11
11
 
12
+ class << self
13
+ alias new pipe
14
+ end
15
+
12
16
  # Override IO#read to behave like IO#readpartial, but still return +nil+
13
17
  # on EOF instead of raising EOFError.
14
- def read(*args)
18
+ def read(len = 16384, buf = '')
15
19
  check_err!
16
- kgio_read(*args) || check_err! || close
20
+ case read_nonblock(len, buf, exception: false)
21
+ when nil
22
+ return check_err! || close
23
+ when :wait_readable
24
+ wait_readable # retry
25
+ else
26
+ return buf
27
+ end while true
17
28
  end
18
29
 
19
30
  def check_err!
@@ -53,7 +53,7 @@ module HTTP_Spew::ClassMethods
53
53
  # If +need+ is fullfilled, it closes all incomplete requests.
54
54
  def wait_mt(need, requests, timeout)
55
55
  ready, failed = [], []
56
- r, w = Kgio::Pipe.new
56
+ r, w = IO.pipe
57
57
  active = []
58
58
  t = [ timeout ]
59
59
  requests.each_with_index do |req, i|
@@ -68,7 +68,7 @@ module HTTP_Spew::ClassMethods
68
68
  end
69
69
  end
70
70
  begin
71
- with_timeout(t) { r.kgio_wait_readable(t[0]) }
71
+ with_timeout(t) { r.wait_readable(t[0]) }
72
72
  req_idx = r.read(2).unpack("v".freeze)[0]
73
73
  thr = active[req_idx]
74
74
  with_timeout(t) { thr.join(t[0]) }
@@ -110,7 +110,7 @@ module HTTP_Spew::ClassMethods
110
110
  break if pollset.empty?
111
111
 
112
112
  busy = pollset.keys
113
- rv = with_timeout(t) { Kgio.poll(pollset, (t[0] * 1000).to_i) } or break
113
+ rv = with_timeout(t) { do_poll(pollset, t[0]) } or break
114
114
  end while t[0] > 0.0 && requests = rv.keys.concat(busy).uniq!
115
115
 
116
116
  ready.concat(failed)
@@ -121,4 +121,32 @@ module HTTP_Spew::ClassMethods
121
121
  end
122
122
  ready
123
123
  end
124
+
125
+ begin
126
+ require 'kgio'
127
+ def do_poll(pollset, sec) # :nodoc:
128
+ Kgio.poll(pollset, (sec * 1000).to_i)
129
+ end
130
+ rescue LoadError
131
+ # emulate Kgio.poll with IO.select
132
+ def do_poll(pollset, sec) # :nodoc:
133
+ rd = []
134
+ wr = []
135
+ pollset.each do |io, events|
136
+ case events
137
+ when :wait_readable
138
+ rd << io
139
+ when :wait_writable
140
+ wr << io
141
+ else
142
+ raise "BUG: unsupported event #{event.inspect} for #{io.inspect}"
143
+ end
144
+ end
145
+ ready = IO.select(rd, wr, nil, sec) or return
146
+ pollset.clear
147
+ ready[0].each { |io| pollset[io] = 1 } # POLLIN
148
+ ready[1].each { |io| pollset[io] = 4 } # POLLOUT
149
+ pollset
150
+ end
151
+ end
124
152
  end
@@ -1,4 +1,6 @@
1
1
  # -*- encoding: binary -*-
2
+ require 'socket'
3
+
2
4
  # This is the base class actually capable of making a normal HTTP request
3
5
  class HTTP_Spew::Request
4
6
 
@@ -21,10 +23,9 @@ class HTTP_Spew::Request
21
23
  #
22
24
  # +sock+ may be the String representing an address created with
23
25
  # +Socket.pack_sockaddr_un+ or +Socket.pack_sockaddr_in+, or it
24
- # may be an actual IO object with Kgio::SocketMethods mixed in
25
- # (e.g. Kgio::Socket)
26
+ # may be an actual Socket object
26
27
  def initialize(env, input, sock, allow = nil)
27
- @to_io = Kgio::SocketMethods === sock ? sock : Kgio::Socket.start(sock)
28
+ @to_io = BasicSocket === sock ? sock : start_sock(sock)
28
29
  if Hash === env
29
30
  @buf, @input = env_to_headers(env, input)
30
31
  else
@@ -37,18 +38,21 @@ class HTTP_Spew::Request
37
38
  # returns :wait_readable or :wait_writable if busy
38
39
  def resume
39
40
  if @buf
40
- case rv = @to_io.kgio_trywrite(@buf)
41
- when String # unlikely
42
- @buf = rv # loop retry, socket buffer could've expanded
43
- when Symbol
44
- return rv
45
- else # done writing, read more
46
- @buf = @input ? @input.read(0x4000, @buf) : nil
41
+ case w = @to_io.write_nonblock(@buf, exception: false)
42
+ when :wait_writable, :wait_readable
43
+ return w
44
+ else # Integer
45
+ len = @buf.size
46
+ if w == len
47
+ @buf = @input ? @input.read(0x4000, @buf) : nil
48
+ else
49
+ tmp = @buf.byteslice(w, len - w)
50
+ @buf.clear
51
+ @buf = tmp # loop retry, socket buffer could've expanded
52
+ end
47
53
  end while @buf
48
- read_response
49
- else
50
- read_response
51
54
  end
55
+ read_response
52
56
  end
53
57
 
54
58
  # returns a 3-element Rack response array on successful completion
@@ -64,7 +68,7 @@ class HTTP_Spew::Request
64
68
  timeout -= (Process.clock_gettime(Process::CLOCK_MONOTONIC) - t0)
65
69
  while :wait_readable == (rv = read_response) && timeout >= 0.0
66
70
  t0 = Process.clock_gettime(Process::CLOCK_MONOTONIC)
67
- @to_io.kgio_wait_readable(timeout) if timeout > 0.0
71
+ @to_io.wait_readable(timeout) if timeout > 0.0
68
72
  timeout -= (Process.clock_gettime(Process::CLOCK_MONOTONIC) - t0)
69
73
  end
70
74
  rv
@@ -78,7 +82,7 @@ class HTTP_Spew::Request
78
82
  # Users do not need to call this directly, +resume+ will return the result
79
83
  # of this.
80
84
  def read_response
81
- buf = @to_io.kgio_trypeek(0x4000) or
85
+ buf = @to_io.recv_nonblock(0x4000, Socket::MSG_PEEK, exception: false) or
82
86
  raise HttpSpew::EOF, "upstream server closed connection", []
83
87
  String === buf or return buf
84
88
 
@@ -91,7 +95,7 @@ class HTTP_Spew::Request
91
95
  end
92
96
 
93
97
  # discard the header data from the socket buffer
94
- (hdr_len -= buf.size) > 0 and @to_io.kgio_read(hdr_len, buf)
98
+ (hdr_len -= buf.size) > 0 and @to_io.read(hdr_len, buf)
95
99
  @response = r << self
96
100
  end
97
101
 
@@ -102,10 +106,15 @@ class HTTP_Spew::Request
102
106
  # Called by Rack servers to write the response to a client
103
107
  def each
104
108
  buf = ""
105
- while @to_io.kgio_read(0x4000, buf)
109
+ case @to_io.read_nonblock(0x4000, buf, exception: false)
110
+ when :wait_readable
111
+ @to_io.wait_readable
112
+ when nil
113
+ buf.clear
114
+ return
115
+ else
106
116
  yield buf
107
- end
108
- buf.clear
117
+ end while true
109
118
  end
110
119
 
111
120
  # Used internally by various HTTP_Spew elements to report errors
@@ -121,4 +130,13 @@ class HTTP_Spew::Request
121
130
  @to_io.close
122
131
  @input = nil
123
132
  end
133
+
134
+ def start_sock(ai)
135
+ ai = Addrinfo.new(ai) unless Addrinfo === ai
136
+ sock = Socket.new(ai.afamily, :SOCK_STREAM)
137
+ case sock.connect_nonblock(ai, exception: false)
138
+ when 0, :wait_writable
139
+ end
140
+ sock
141
+ end
124
142
  end
@@ -19,7 +19,8 @@ class TestHitNRun < Test::Unit::TestCase
19
19
  end
20
20
 
21
21
  def test_request_with_existing_socket
22
- sock = Kgio::Socket.new(@sockaddr)
22
+ sock = TCPSocket.new(@addr, @port)
23
+ assert(BasicSocket === sock)
23
24
  req = HTTP_Spew::HitNRun.new(@env, nil, sock)
24
25
  assert_equal sock, req.to_io
25
26
  assert_nothing_raised { req.close }
@@ -30,8 +31,7 @@ class TestHitNRun < Test::Unit::TestCase
30
31
  req = HTTP_Spew::HitNRun.new(@env, nil, @sockaddr)
31
32
  sym = req.resume
32
33
  if sym == :wait_writable
33
- set = Kgio.poll({req => sym}, 100)
34
- assert_equal [ req ], set.keys
34
+ assert req.to_io.wait_writable(0.1)
35
35
  sym = req.resume
36
36
  end
37
37
  assert_equal HTTP_Spew::HitNRun::RESPONSE.object_id, sym.object_id
@@ -40,7 +40,7 @@ class TestHitNRun < Test::Unit::TestCase
40
40
  def test_request_loop
41
41
  req = HTTP_Spew::HitNRun.new(@env, nil, @sockaddr)
42
42
  until Array === (rv = req.resume)
43
- Kgio.poll(req => rv)
43
+ req.__send__(rv)
44
44
  end
45
45
  assert_equal HTTP_Spew::HitNRun::RESPONSE.object_id, rv.object_id
46
46
  end
@@ -19,7 +19,7 @@ class TestRequest < Test::Unit::TestCase
19
19
  end
20
20
 
21
21
  def test_request_with_existing_socket
22
- sock = Kgio::Socket.new(@sockaddr)
22
+ sock = TCPSocket.new(@addr, @port)
23
23
  req = HTTP_Spew::Request.new(@env, nil, sock)
24
24
  assert_equal sock, req.to_io
25
25
  assert_nothing_raised { req.close }
@@ -31,13 +31,11 @@ class TestRequest < Test::Unit::TestCase
31
31
  sym = req.resume
32
32
  assert_kind_of(Symbol, sym)
33
33
  if sym == :wait_writable
34
- set = Kgio.poll({req => sym}, 1000)
35
- assert_equal [ req ], set.keys
34
+ assert req.to_io.wait_writable(1)
36
35
  sym = req.resume
37
36
  end
38
37
  assert_equal :wait_readable, sym
39
- set = Kgio.poll({req => sym}, 1000)
40
- assert_equal [ req ], set.keys
38
+ assert req.to_io.wait_readable(1)
41
39
  rv = req.resume
42
40
  assert_equal req, rv[2]
43
41
  end
@@ -45,7 +43,7 @@ class TestRequest < Test::Unit::TestCase
45
43
  def test_request_loop
46
44
  req = HTTP_Spew::Request.new(@env, nil, @sockaddr)
47
45
  until Array === (rv = req.resume)
48
- Kgio.poll(req => rv)
46
+ req.to_io.__send__(rv) # wait_readable/wait_writable
49
47
  end
50
48
  assert_kind_of Array, rv
51
49
  assert_equal 3, rv.size
@@ -19,7 +19,7 @@ class TestRequest < Test::Unit::TestCase
19
19
  end
20
20
 
21
21
  def test_request_with_existing_socket
22
- sock = Kgio::Socket.new(@sockaddr)
22
+ sock = TCPSocket.new(@addr, @port)
23
23
  req = HTTP_Spew::Request.new(@env, nil, sock)
24
24
  assert_equal sock, req.to_io
25
25
  assert_nothing_raised { req.close }
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: http_spew
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0
4
+ version: 0.7.0
5
5
  platform: ruby
6
6
  authors:
7
- - kcar hackers
7
+ - http_spew hackers
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-11-05 00:00:00.000000000 Z
11
+ date: 2017-06-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: kcar
@@ -30,39 +30,11 @@ dependencies:
30
30
  - - ">="
31
31
  - !ruby/object:Gem::Version
32
32
  version: 0.3.1
33
- - !ruby/object:Gem::Dependency
34
- name: kgio
35
- requirement: !ruby/object:Gem::Requirement
36
- requirements:
37
- - - "~>"
38
- - !ruby/object:Gem::Version
39
- version: '2.6'
40
- type: :runtime
41
- prerelease: false
42
- version_requirements: !ruby/object:Gem::Requirement
43
- requirements:
44
- - - "~>"
45
- - !ruby/object:Gem::Version
46
- version: '2.6'
47
- - !ruby/object:Gem::Dependency
48
- name: olddoc
49
- requirement: !ruby/object:Gem::Requirement
50
- requirements:
51
- - - "~>"
52
- - !ruby/object:Gem::Version
53
- version: '1.0'
54
- type: :development
55
- prerelease: false
56
- version_requirements: !ruby/object:Gem::Requirement
57
- requirements:
58
- - - "~>"
59
- - !ruby/object:Gem::Version
60
- version: '1.0'
61
33
  description: |-
62
34
  Do not use HTTP Spew for connecting to servers outside of your LAN.
63
35
  Do not use HTTP Spew without the permission of your server admins.
64
36
  Use HTTP Spew if you wish you could kinda multicast with HTTP...
65
- email: kcar@bogomips.org
37
+ email: http_spew-public@bogomips.org
66
38
  executables: []
67
39
  extensions: []
68
40
  extra_rdoc_files:
@@ -70,15 +42,6 @@ extra_rdoc_files:
70
42
  - README
71
43
  - NEWS
72
44
  - LATEST
73
- - lib/http_spew.rb
74
- - lib/http_spew/chunky_pipe.rb
75
- - lib/http_spew/class_methods.rb
76
- - lib/http_spew/content_md5.rb
77
- - lib/http_spew/headers.rb
78
- - lib/http_spew/hit_n_run.rb
79
- - lib/http_spew/input_spray.rb
80
- - lib/http_spew/request.rb
81
- - lib/http_spew/version.rb
82
45
  files:
83
46
  - ".document"
84
47
  - ".gitignore"
@@ -131,7 +94,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
131
94
  requirements:
132
95
  - - ">="
133
96
  - !ruby/object:Gem::Version
134
- version: '2.1'
97
+ version: '2.3'
135
98
  required_rubygems_version: !ruby/object:Gem::Requirement
136
99
  requirements:
137
100
  - - ">="
@@ -139,10 +102,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
139
102
  version: '0'
140
103
  requirements: []
141
104
  rubyforge_project:
142
- rubygems_version: 2.6.7
105
+ rubygems_version: 2.6.12
143
106
  signing_key:
144
107
  specification_version: 4
145
- summary: LAN-only HTTP spam^H^H^H^Hclient for Ruby
108
+ summary: HTTP Spew - LAN-only HTTP spam^H^H^H^Hclient for Ruby
146
109
  test_files:
147
110
  - test/test_input_spray_with_md5.rb
148
111
  - test/test_mirror.rb