-
-
Notifications
You must be signed in to change notification settings - Fork 309
/
chunking-test.coffee
48 lines (42 loc) · 1.42 KB
/
chunking-test.coffee
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
# ***** BEGIN LICENSE BLOCK *****
# Copyright (c) 2011-2012 VMware, Inc.
#
# For the license see COPYING.
# ***** END LICENSE BLOCK *****
utils = require('./utils')
exports.app =
# TODO: remove in next major release
chunking_test: (req, res, _, next_filter) ->
res.setHeader('Content-Type', 'application/javascript; charset=UTF-8')
res.writeHead(200)
write = (payload) =>
try
res.write(payload + '\n')
catch x
return
utils.timeout_chain([
# IE requires 2KB prelude
[0, => write('h')],
[1, => write(Array(2049).join(' ') + 'h')],
[5, => write('h')],
[25, => write('h')],
[125, => write('h')],
[625, => write('h')],
[3125, => write('h'); res.end()],
])
return true
info: (req, res, _) ->
info = {
websocket: @options.websocket,
origins: ['*:*'],
cookie_needed: not not @options.jsessionid,
entropy: utils.random32(),
}
res.setHeader('Content-Type', 'application/json; charset=UTF-8')
res.writeHead(200)
res.end(JSON.stringify(info))
info_options: (req, res) ->
res.statusCode = 204
res.setHeader('Access-Control-Allow-Methods', 'OPTIONS, GET')
res.setHeader('Access-Control-Max-Age', res.cache_for)
return ''