ftw 0.0.19 → 0.0.20
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.
- data/lib/ftw/agent.rb +16 -3
- data/lib/ftw/protocol.rb +16 -3
- data/lib/ftw/version.rb +1 -1
- data/lib/ftw/websocket/rack.rb +10 -0
- metadata +24 -24
data/lib/ftw/agent.rb
CHANGED
@@ -209,6 +209,7 @@ class FTW::Agent
|
|
209
209
|
req.headers["Upgrade"] = protocol
|
210
210
|
response = execute(req)
|
211
211
|
if response.status == 101
|
212
|
+
# Success, return the response object and the connection to hand off.
|
212
213
|
return response, response.body
|
213
214
|
else
|
214
215
|
return response, nil
|
@@ -230,13 +231,24 @@ class FTW::Agent
|
|
230
231
|
if ws.handshake_ok?(response)
|
231
232
|
# response.body is a FTW::Connection
|
232
233
|
ws.connection = response.body
|
234
|
+
|
235
|
+
# There seems to be a bug in http_parser.rb where websocket responses
|
236
|
+
# lead with a newline for some reason. It's like the header terminator
|
237
|
+
# CRLF still has the LF character left in the buffer. Work around it.
|
238
|
+
data = response.body.read
|
239
|
+
if data[0] == "\n"
|
240
|
+
response.body.pushback(data[1..-1])
|
241
|
+
else
|
242
|
+
response.body.pushback(data)
|
243
|
+
end
|
244
|
+
|
233
245
|
return ws
|
234
246
|
else
|
235
247
|
return response
|
236
248
|
end
|
237
249
|
end # def websocket!
|
238
250
|
|
239
|
-
#
|
251
|
+
# Build a request. Returns a FTW::Request object.
|
240
252
|
#
|
241
253
|
# Arguments:
|
242
254
|
#
|
@@ -283,7 +295,8 @@ class FTW::Agent
|
|
283
295
|
def execute(request)
|
284
296
|
# TODO(sissel): Make redirection-following optional, but default.
|
285
297
|
|
286
|
-
connection, error = connect(request.headers["Host"], request.port,
|
298
|
+
connection, error = connect(request.headers["Host"], request.port,
|
299
|
+
request.protocol == "https")
|
287
300
|
if !error.nil?
|
288
301
|
p :error => error
|
289
302
|
raise error
|
@@ -400,5 +413,5 @@ class FTW::Agent
|
|
400
413
|
# TODO(sissel): Implement methods for managing the cookie store
|
401
414
|
# TODO(sissel): Implement methods for managing the cache
|
402
415
|
# TODO(sissel): Implement configuration stuff? Is FTW::Agent::Configuration the best way?
|
403
|
-
public(:initialize, :execute, :websocket!, :upgrade!, :shutdown)
|
416
|
+
public(:initialize, :execute, :websocket!, :upgrade!, :shutdown, :request)
|
404
417
|
end # class FTW::Agent
|
data/lib/ftw/protocol.rb
CHANGED
@@ -114,12 +114,25 @@ module FTW::Protocol
|
|
114
114
|
# If this is a poolable resource, release it (like a FTW::Connection)
|
115
115
|
@body.release if @body.respond_to?(:release)
|
116
116
|
elsif !@body.nil?
|
117
|
-
|
117
|
+
block.call(@body)
|
118
118
|
end
|
119
119
|
end # def read_http_body
|
120
120
|
|
121
|
-
#
|
122
|
-
|
121
|
+
# Read the body of this message. The block is called with chunks of the
|
122
|
+
# response as they are read in.
|
123
|
+
#
|
124
|
+
# This method is generally only called by http clients, not servers.
|
125
|
+
#
|
126
|
+
# If no block is given, the entire response body is returned as a string.
|
127
|
+
def read_body(&block)
|
128
|
+
if !block_given?
|
129
|
+
content = ""
|
130
|
+
read_http_body { |chunk| content << chunk }
|
131
|
+
return content
|
132
|
+
else
|
133
|
+
read_http_body(&block)
|
134
|
+
end
|
135
|
+
end # def read_body
|
123
136
|
|
124
137
|
# Read the length bytes from the body. Yield each chunk read to the block
|
125
138
|
# given. This method is generally only called by http clients, not servers.
|
data/lib/ftw/version.rb
CHANGED
data/lib/ftw/websocket/rack.rb
CHANGED
@@ -105,6 +105,16 @@ class FTW::WebSocket::Rack
|
|
105
105
|
# end
|
106
106
|
def each
|
107
107
|
connection = @env["ftw.connection"]
|
108
|
+
# There seems to be a bug in http_parser.rb where websocket responses
|
109
|
+
# lead with a newline for some reason. It's like the header terminator
|
110
|
+
# CRLF still has the LF character left in the buffer. Work around it.
|
111
|
+
data = connection.read
|
112
|
+
if data[0] == "\n"
|
113
|
+
connection.pushback(data[1..-1])
|
114
|
+
else
|
115
|
+
connection.pushback(data)
|
116
|
+
end
|
117
|
+
|
108
118
|
while true
|
109
119
|
begin
|
110
120
|
data = connection.read(16384)
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ftw
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.20
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-09-11 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: json
|
@@ -115,41 +115,41 @@ executables: []
|
|
115
115
|
extensions: []
|
116
116
|
extra_rdoc_files: []
|
117
117
|
files:
|
118
|
-
- lib/rack/handler/ftw.rb
|
119
118
|
- lib/ftw.rb
|
120
|
-
- lib/ftw
|
119
|
+
- lib/rack/handler/ftw.rb
|
121
120
|
- lib/ftw/cacert.pem
|
122
|
-
- lib/ftw/
|
123
|
-
- lib/ftw/
|
124
|
-
- lib/ftw/
|
125
|
-
- lib/ftw/
|
121
|
+
- lib/ftw/crlf.rb
|
122
|
+
- lib/ftw/singleton.rb
|
123
|
+
- lib/ftw/dns/hash.rb
|
124
|
+
- lib/ftw/dns/dns.rb
|
126
125
|
- lib/ftw/poolable.rb
|
127
|
-
- lib/ftw/
|
128
|
-
- lib/ftw/
|
126
|
+
- lib/ftw/protocol.rb
|
127
|
+
- lib/ftw/namespace.rb
|
128
|
+
- lib/ftw/cookies.rb
|
129
129
|
- lib/ftw/agent.rb
|
130
|
-
- lib/ftw/
|
131
|
-
- lib/ftw/
|
130
|
+
- lib/ftw/websocket/parser.rb
|
131
|
+
- lib/ftw/websocket/rack.rb
|
132
|
+
- lib/ftw/websocket/constants.rb
|
133
|
+
- lib/ftw/websocket/writer.rb
|
132
134
|
- lib/ftw/websocket.rb
|
133
|
-
- lib/ftw/http/message.rb
|
134
135
|
- lib/ftw/http/headers.rb
|
136
|
+
- lib/ftw/http/message.rb
|
137
|
+
- lib/ftw/dns.rb
|
138
|
+
- lib/ftw/server.rb
|
139
|
+
- lib/ftw/version.rb
|
135
140
|
- lib/ftw/agent/configuration.rb
|
136
141
|
- lib/ftw/request.rb
|
137
|
-
- lib/ftw/protocol.rb
|
138
142
|
- lib/ftw/response.rb
|
139
|
-
- lib/ftw/
|
140
|
-
- lib/ftw/dns/dns.rb
|
141
|
-
- lib/ftw/dns/hash.rb
|
142
|
-
- lib/ftw/cookies.rb
|
143
|
-
- lib/ftw/singleton.rb
|
144
|
-
- lib/ftw/crlf.rb
|
143
|
+
- lib/ftw/pool.rb
|
145
144
|
- lib/ftw/webserver.rb
|
146
|
-
-
|
145
|
+
- lib/ftw/connection.rb
|
147
146
|
- test/docs.rb
|
147
|
+
- test/all.rb
|
148
|
+
- test/ftw/crlf.rb
|
149
|
+
- test/ftw/singleton.rb
|
148
150
|
- test/ftw/http/dns.rb
|
149
151
|
- test/ftw/http/headers.rb
|
150
|
-
- test/
|
151
|
-
- test/ftw/crlf.rb
|
152
|
-
- test/all.rb
|
152
|
+
- test/testing.rb
|
153
153
|
- README.md
|
154
154
|
homepage: http://github.com/jordansissel/ruby-ftw
|
155
155
|
licenses:
|