-
-
Notifications
You must be signed in to change notification settings - Fork 15
/
NOTES
72 lines (48 loc) · 2.41 KB
/
NOTES
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
consternant: @botanicus unicorn enables Rack::Chunked since v4.1.0 bit.ly/cag377
majek04: @botanicus Thin doesn't do proper 'transfer-encoding: chunked' but it can do a very similar thing (relying on 'connection: close').
judofyr: @botanicus Mongrel supports streaming body.each. Thin/Unicorn supports streaming through env['async.callback']
majek:
In SRS we were using Sinatra with Thin. To get long polling working,
we used "Thin::Connection::AsyncResponse" magic.
The views looked like that:
get '/instances/:ver' do
some_waiting_on_eventmachine_here do |stuff|
finish JSON.pretty_generate stuff
end
Thin::Connection::AsyncResponse
end
Where finish is:
def finish(data, status=200, user_headers={})
headers = {'Content-Type' => 'text/plain'}.update( user_headers )
data = [data] if data.is_a? String
env['async.callback'].call [status, headers, data]
end
Quite hacky, and Thin-dependent, but hey, it works.
Of course websockets are a bigger issue. You can take a
look at the eventmachine-websockety think you've found
and see if it integrates with any http server.
majek:
>> Some prose:
>> http://macournoyer.com/blog/2009/06/04/pusher-and-async-with-thin/
This article explains everything. Also take a look:
https://github.com/macournoyer/pusher
I've attached a dumb example of how to do streaming (multiple responses).
It doesn't do "Transfer-Encoding: chunked", (it does the http/1.0
compatible thing - "Connection: close" and no "content-length")
but it doesn't matter.
(You can easily emulate proper chunking for 1.1 clients:
just set the header and send data with leading length. But there is
little benefit for that, as thin will not try to reuse connections
using "connection: keepalive", so feel free to ignore the problem for
now)
majek: http://cramp.in
http://rainbows.rubyforge.org/Rainbows/EventMachine.html
https://github.com/imanel/websocket-rack
http://stackoverflow.com/questions/2999430/any-success-with-sinatra-working-together-with-eventmachine-websockets/5491157#5491157
https://github.com/rack/rack/blob/master/lib/rack/chunked.rb
http://www.igvita.com/2011/03/08/goliath-non-blocking-ruby-19-web-server/
https://github.com/macournoyer/pusher
https://github.com/sockjs/sockjs-client/blob/master/tests/sockjs_app.js
https://github.com/imanel/websocket-rack/tree/master/lib
http://www.igvita.com/2009/12/22/ruby-websockets-tcp-for-the-browser
https://gist.github.com/1138480