ftw 0.0.39 → 0.0.40

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,7 @@
1
1
  ---
2
- !binary "U0hBMQ==":
3
- metadata.gz: !binary |-
4
- ZGM2YzlmODMwN2RjNzU0YTNhNmU3ZDBlNmNiOGY4ZmNmZTNiY2NlOA==
5
- data.tar.gz: !binary |-
6
- Y2VhYTRmMzNiNzM1NzI3YmMxNjllZDA1MGVlNjVkODE4ZTM4Yzc2OQ==
2
+ SHA1:
3
+ metadata.gz: 1ab7afb8f3c6e07bf4f80b2635bff119eef99e04
4
+ data.tar.gz: 5b59a556ba16516104ae26dc2b80ad87d08bfce8
7
5
  SHA512:
8
- metadata.gz: !binary |-
9
- NjlkMDBkNTAxMTA3NWM5NmU3ZTJmOTc5OWZhMzhjOWY5ZDM4MzMxYjllZmQ3
10
- OWJkNzc0NjdmZjMzOGNhYWYwNWNiYmQyZjE0MDVmYmQ2MTg5ODM2MmE1NDcx
11
- YjMxZTk4MzJhYmI1ZjFlNmI0OWIxNDMxYTA3N2ZiNjQ3YWE3MGQ=
12
- data.tar.gz: !binary |-
13
- NzA4ZjlmMTYzOThjMDRjZWI2MjkxNmYzZTExZTI0ZDkxY2MyNjM2MTFlYWNi
14
- ZWUyNjFiZjZhMWNjZTRiNjkyMTIzNjkwZDQzZWU1YWRiMWU4ZTUyZDg2Yjkx
15
- YjA4MTFiZTRkYjQyOWNjYzk3N2MwNGQ5MjMxNjEwZmI0MjMzNzk=
6
+ metadata.gz: 6186e1580975f891bfe1f2f774def4c193abaf4db82fd2b20d845cbb661a998892467ba73a2d260f4c686e206a82de2cc907a9dfa319a1fd46edc5849c60e661
7
+ data.tar.gz: 35836d9e9d0ea74922d84dbc9115f00885b4e2710c6d71904d70fdbd09931a684c9100395abe34c7051cabeb083e2529954dffc0836b996a79aa4de09511a26e
data/lib/ftw/agent.rb CHANGED
@@ -208,11 +208,13 @@ class FTW::Agent
208
208
  m = name.upcase
209
209
 
210
210
  # 'def get' (put, post, etc)
211
+ public
211
212
  define_method(name.to_sym) do |uri, options={}|
212
213
  return request(m, uri, options)
213
214
  end
214
215
 
215
216
  # 'def get!' (put!, post!, etc)
217
+ public
216
218
  define_method("#{name}!".to_sym) do |uri, options={}|
217
219
  return execute(request(m, uri, options))
218
220
  end
@@ -244,6 +244,8 @@ class FTW::Connection
244
244
  data << @read_buffer
245
245
  return data
246
246
  rescue EOFError => e
247
+ @socket.close
248
+ @connected = false
247
249
  raise e
248
250
  end
249
251
  else
@@ -329,13 +331,26 @@ class FTW::Connection
329
331
  # If you use VERIFY_NONE, you are removing the trust feature of TLS. Don't do that.
330
332
  # Encryption without trust means you don't know who you are talking to.
331
333
  sslcontext.verify_mode = OpenSSL::SSL::VERIFY_PEER
334
+
335
+ # ruby-core is refusing to patch ruby's default openssl settings to be more
336
+ # secure, so let's fix that here. The next few lines setting options and
337
+ # ciphers come from jmhodges proposed patch
338
+ ssloptions = OpenSSL::SSL::OP_ALL
339
+ if defined?(OpenSSL::SSL::OP_DONT_INSERT_EMPTY_FRAGMENTS)
340
+ ssloptions &= ~OpenSSL::SSL::OP_DONT_INSERT_EMPTY_FRAGMENTS
341
+ end
342
+ if defined?(OpenSSL::SSL::OP_NO_COMPRESSION)
343
+ ssloptions |= OpenSSL::SSL::OP_NO_COMPRESSION
344
+ end
345
+ sslcontext.options = ssloptions
346
+ sslcontext.ciphers = "DEFAULT:!aNULL:!eNULL:!LOW:!EXPORT:!SSLv2"
347
+
332
348
  sslcontext.verify_callback = proc do |*args|
333
349
  @logger.debug("Verify peer via FTW::Connection#secure", :callback => settings[:verify_callback])
334
350
  if settings[:verify_callback].respond_to?(:call)
335
351
  settings[:verify_callback].call(*args)
336
352
  end
337
353
  end
338
- sslcontext.ssl_version = :TLSv1
339
354
  sslcontext.cert_store = options[:certificate_store]
340
355
  @socket = OpenSSL::SSL::SSLSocket.new(@socket, sslcontext)
341
356
 
data/lib/ftw/pool.rb CHANGED
@@ -40,6 +40,7 @@ class FTW::Pool
40
40
  # end
41
41
  def fetch(identifier, &default_block)
42
42
  @lock.synchronize do
43
+ @pool[identifier].delete_if { |o| o.available? && !o.connected? }
43
44
  object = @pool[identifier].find { |o| o.available? }
44
45
  return object if !object.nil?
45
46
  end
data/lib/ftw/protocol.rb CHANGED
@@ -74,29 +74,45 @@ module FTW::Protocol
74
74
 
75
75
  def write_http_body_chunked(body, io)
76
76
  if body.is_a?(String)
77
- io.write(encode_chunked(body))
77
+ write_all( io, encode_chunked(body))
78
78
  elsif body.respond_to?(:sysread)
79
- true while io.write(encode_chunked(body.sysread(16384)))
79
+ begin
80
+ while cont = body.sysread(16384)
81
+ write_all( io, encode_chunked(cont))
82
+ end
83
+ rescue EOFError
84
+ end
80
85
  elsif body.respond_to?(:read)
81
- true while io.write(encode_chunked(body.read(16384)))
86
+ while cont = body.read(16384)
87
+ write_all( io, encode_chunked(cont) )
88
+ end
82
89
  elsif body.respond_to?(:each)
83
- body.each { |s| io.write(encode_chunked(s)) }
90
+ body.each { |s| write_all( io, encode_chunked(s)) }
84
91
  end
85
92
 
86
93
  # The terminating chunk is an empty one.
87
- io.write(encode_chunked(""))
94
+ write_all(io, encode_chunked(""))
88
95
  end # def write_http_body_chunked
89
96
 
90
97
  def write_http_body_normal(body, io)
91
98
  if body.is_a?(String)
92
- io.write(body)
99
+ write_all(io, body)
93
100
  elsif body.respond_to?(:read)
94
- true while io.write(body.read(16384))
101
+ while cont = body.read(16384)
102
+ write_all(io, cont)
103
+ end
95
104
  elsif body.respond_to?(:each)
96
- body.each { |s| io.write(s) }
105
+ body.each { |s| write_all( io, s) }
97
106
  end
98
107
  end # def write_http_body_normal
99
108
 
109
+ def write_all(io, string)
110
+ while string.bytesize > 0
111
+ w = io.write(string)
112
+ string = string[w..-1]
113
+ end
114
+ end # def write_all
115
+
100
116
  # Read the body of this message. The block is called with chunks of the
101
117
  # response as they are read in.
102
118
  #
data/lib/ftw/version.rb CHANGED
@@ -3,5 +3,5 @@ require "ftw/namespace"
3
3
  # :nodoc:
4
4
  module FTW
5
5
  # The version of this library
6
- VERSION = "0.0.39"
6
+ VERSION = "0.0.40"
7
7
  end
@@ -0,0 +1,79 @@
1
+ #require File.join(File.expand_path(__FILE__).sub(/\/ftw\/.*/, "/testing"))
2
+ require 'ftw/protocol'
3
+ require 'stringio'
4
+
5
+ describe FTW::Protocol do
6
+
7
+ class OnlySysread < Struct.new(:io)
8
+ def sysread(*args)
9
+ io.sysread(*args)
10
+ end
11
+ end
12
+
13
+ class OnlyRead < Struct.new(:io)
14
+ def read(*args)
15
+ io.read(*args)
16
+ end
17
+ end
18
+
19
+ test "reading body via #read" do
20
+ protocol = Object.new
21
+ protocol.extend FTW::Protocol
22
+
23
+ output = StringIO.new
24
+ input = OnlyRead.new( StringIO.new('Some example input') )
25
+
26
+ protocol.write_http_body(input, output, false)
27
+
28
+ output.rewind
29
+ assert_equal( output.string, 'Some example input')
30
+ end
31
+
32
+ test "reading body via #sysread chunked" do
33
+ protocol = Object.new
34
+ protocol.extend FTW::Protocol
35
+
36
+ output = StringIO.new
37
+ input = OnlySysread.new( StringIO.new('Some example input') )
38
+
39
+ protocol.write_http_body(input, output, true)
40
+
41
+ output.rewind
42
+ assert_equal( output.string, "12\r\nSome example input\r\n0\r\n\r\n")
43
+ end
44
+
45
+ test "reading body via #read chunked" do
46
+ protocol = Object.new
47
+ protocol.extend FTW::Protocol
48
+
49
+ output = StringIO.new
50
+ input = OnlyRead.new( StringIO.new('Some example input') )
51
+
52
+ protocol.write_http_body(input, output, true)
53
+
54
+ output.rewind
55
+ assert_equal( output.string, "12\r\nSome example input\r\n0\r\n\r\n")
56
+ end
57
+
58
+ class OneByteWriter < Struct.new(:io)
59
+
60
+ def write( str )
61
+ io.write(str[0..1])
62
+ end
63
+
64
+ end
65
+
66
+ test "writing partially" do
67
+ protocol = Object.new
68
+ protocol.extend FTW::Protocol
69
+
70
+ output = OneByteWriter.new( StringIO.new )
71
+ input = OnlyRead.new( StringIO.new('Some example input') )
72
+
73
+ protocol.write_http_body(input, output, true)
74
+
75
+ output.io.rewind
76
+ assert_equal( output.io.string, "12\r\nSome example input\r\n0\r\n\r\n")
77
+ end
78
+
79
+ end
metadata CHANGED
@@ -1,27 +1,27 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ftw
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.39
4
+ version: 0.0.40
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jordan Sissel
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-12-16 00:00:00.000000000 Z
11
+ date: 2014-09-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: cabin
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ! '>'
17
+ - - ">"
18
18
  - !ruby/object:Gem::Version
19
19
  version: '0'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ! '>'
24
+ - - ">"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
27
  - !ruby/object:Gem::Dependency
@@ -42,42 +42,42 @@ dependencies:
42
42
  name: addressable
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - ! '>='
45
+ - - ">="
46
46
  - !ruby/object:Gem::Version
47
47
  version: '0'
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - ! '>='
52
+ - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: backports
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - ! '>='
59
+ - - ">="
60
60
  - !ruby/object:Gem::Version
61
61
  version: 2.6.2
62
62
  type: :runtime
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - ! '>='
66
+ - - ">="
67
67
  - !ruby/object:Gem::Version
68
68
  version: 2.6.2
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: minitest
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - ! '>'
73
+ - - ">"
74
74
  - !ruby/object:Gem::Version
75
75
  version: '0'
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - ! '>'
80
+ - - ">"
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
83
  description: For The Web. Trying to build a solid and sane API for client and server
@@ -88,42 +88,43 @@ executables: []
88
88
  extensions: []
89
89
  extra_rdoc_files: []
90
90
  files:
91
- - lib/rack/handler/ftw.rb
92
- - lib/ftw/dns.rb
93
- - lib/ftw/dns/dns.rb
94
- - lib/ftw/dns/hash.rb
91
+ - README.md
92
+ - lib/ftw.rb
95
93
  - lib/ftw/agent.rb
96
94
  - lib/ftw/agent/configuration.rb
97
- - lib/ftw/singleton.rb
98
- - lib/ftw/websocket.rb
95
+ - lib/ftw/cacert.pem
99
96
  - lib/ftw/connection.rb
97
+ - lib/ftw/cookies.rb
98
+ - lib/ftw/crlf.rb
99
+ - lib/ftw/dns.rb
100
+ - lib/ftw/dns/dns.rb
101
+ - lib/ftw/dns/hash.rb
100
102
  - lib/ftw/http/headers.rb
101
103
  - lib/ftw/http/message.rb
104
+ - lib/ftw/namespace.rb
105
+ - lib/ftw/pool.rb
102
106
  - lib/ftw/poolable.rb
103
- - lib/ftw/server.rb
104
- - lib/ftw/response.rb
105
107
  - lib/ftw/protocol.rb
106
- - lib/ftw/cacert.pem
107
- - lib/ftw/version.rb
108
- - lib/ftw/namespace.rb
109
108
  - lib/ftw/request.rb
110
- - lib/ftw/crlf.rb
111
- - lib/ftw/pool.rb
109
+ - lib/ftw/response.rb
110
+ - lib/ftw/server.rb
111
+ - lib/ftw/singleton.rb
112
+ - lib/ftw/version.rb
112
113
  - lib/ftw/webserver.rb
113
- - lib/ftw/websocket/writer.rb
114
- - lib/ftw/websocket/rack.rb
115
- - lib/ftw/websocket/parser.rb
114
+ - lib/ftw/websocket.rb
116
115
  - lib/ftw/websocket/constants.rb
117
- - lib/ftw/cookies.rb
118
- - lib/ftw.rb
119
- - test/testing.rb
116
+ - lib/ftw/websocket/parser.rb
117
+ - lib/ftw/websocket/rack.rb
118
+ - lib/ftw/websocket/writer.rb
119
+ - lib/rack/handler/ftw.rb
120
120
  - test/all.rb
121
- - test/ftw/singleton.rb
121
+ - test/docs.rb
122
+ - test/ftw/crlf.rb
122
123
  - test/ftw/http/dns.rb
123
124
  - test/ftw/http/headers.rb
124
- - test/ftw/crlf.rb
125
- - test/docs.rb
126
- - README.md
125
+ - test/ftw/protocol.rb
126
+ - test/ftw/singleton.rb
127
+ - test/testing.rb
127
128
  homepage: http://github.com/jordansissel/ruby-ftw
128
129
  licenses:
129
130
  - Apache License (2.0)
@@ -135,17 +136,17 @@ require_paths:
135
136
  - lib
136
137
  required_ruby_version: !ruby/object:Gem::Requirement
137
138
  requirements:
138
- - - ! '>='
139
+ - - ">="
139
140
  - !ruby/object:Gem::Version
140
141
  version: '0'
141
142
  required_rubygems_version: !ruby/object:Gem::Requirement
142
143
  requirements:
143
- - - ! '>='
144
+ - - ">="
144
145
  - !ruby/object:Gem::Version
145
146
  version: '0'
146
147
  requirements: []
147
148
  rubyforge_project:
148
- rubygems_version: 2.1.10
149
+ rubygems_version: 2.2.2
149
150
  signing_key:
150
151
  specification_version: 4
151
152
  summary: For The Web. Trying to build a solid and sane API for client and server web