opal-up 0.0.7 → 0.0.9
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.
- checksums.yaml +4 -4
- data/ext/up_ext/Loop.h +1 -1
- data/ext/up_ext/WebSocketProtocol.h +1 -1
- data/ext/up_ext/up_ext.c +15 -12
- data/lib/up/bun/server.rb +8 -4
- data/lib/up/ruby/cluster.rb +15 -3
- data/lib/up/u_web_socket/server.rb +8 -4
- data/lib/up/version.rb +1 -1
- metadata +1 -2
- data/lib/up/bun/rack_env.rb +0 -92
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3bb6a2cde4f3f4cc8415d17f9d6c471dd5a991cf8ef3a588c528370b4330683d
|
4
|
+
data.tar.gz: 697d463336883f4259a27804239642fca35915f7991de7cc92260b6adcda44e1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: '09e5af566f909d626a00e0b865b5bb7d7e717d7488f7111a5cc6b9fd8ad2b53d2c9e9aa651492ff76e6ef5eb61da63f208d719af2a593b458033b1eec3a90a10'
|
7
|
+
data.tar.gz: f96190488e44fac00d338f639b9167e80ac0a48cd9ee108a75474e99d982834514b94f4a01c8769ef399091c6cab2c6e54381e3e1e524215b2a028a8039abf75
|
data/ext/up_ext/Loop.h
CHANGED
data/ext/up_ext/up_ext.c
CHANGED
@@ -26,6 +26,7 @@ static ID at_instance;
|
|
26
26
|
static ID at_member_id;
|
27
27
|
static ID at_members;
|
28
28
|
static ID at_open;
|
29
|
+
static ID at_port;
|
29
30
|
static ID at_protocol;
|
30
31
|
static ID at_secret;
|
31
32
|
static ID at_server;
|
@@ -142,9 +143,17 @@ static void up_internal_req_header_handler(const char *h, size_t h_len,
|
|
142
143
|
}
|
143
144
|
|
144
145
|
header_key[h_len + 5] = '\0';
|
145
|
-
|
146
|
-
|
147
|
-
|
146
|
+
if (header_key[5] == 'C' &&
|
147
|
+
((strncmp(header_key + 5, "CONTENT_TYPE", 12) == 0) ||
|
148
|
+
(strncmp(header_key + 5, "CONTENT_LENGTH", 14) == 0))) {
|
149
|
+
rb_hash_aset((VALUE)renv,
|
150
|
+
rb_enc_str_new(header_key + 5, h_len, binary_encoding),
|
151
|
+
rb_enc_str_new(v, v_len, binary_encoding));
|
152
|
+
} else {
|
153
|
+
rb_hash_aset((VALUE)renv,
|
154
|
+
rb_enc_str_new(header_key, h_len + 5, binary_encoding),
|
155
|
+
rb_enc_str_new(v, v_len, binary_encoding));
|
156
|
+
}
|
148
157
|
}
|
149
158
|
|
150
159
|
static void up_server_prepare_env(VALUE renv, uws_req_t *req) {
|
@@ -629,6 +638,8 @@ static VALUE up_server_init(int argc, VALUE *argv, VALUE self) {
|
|
629
638
|
s->port = rport;
|
630
639
|
s->logger = rargs[3];
|
631
640
|
|
641
|
+
rb_ivar_set(self, at_port, s->port);
|
642
|
+
|
632
643
|
return self;
|
633
644
|
}
|
634
645
|
|
@@ -918,15 +929,6 @@ void up_setup_rack_env_template(void) {
|
|
918
929
|
// A common object interface for logging messages
|
919
930
|
up_hash_set(rack_env_template, "rack.logger", default_logger);
|
920
931
|
|
921
|
-
// An Integer hint to the multipart parser as to what chunk size to use for
|
922
|
-
// reads and writes.
|
923
|
-
up_hash_set(rack_env_template, "rack.multipart.buffer_size", INT2FIX(4096));
|
924
|
-
|
925
|
-
// An object responding to #call with two arguments, the filename and
|
926
|
-
// content_type given for the multipart form field, and returning an IO-like
|
927
|
-
// object that responds to #<< and optionally #rewind.
|
928
|
-
// up_hash_set(rack_env_template, "rack.multipart.tempfile_factory", Qnil);
|
929
|
-
|
930
932
|
// An array of callables run by the server after the response has been
|
931
933
|
// processed.
|
932
934
|
// up_hash_set(rack_env_template, "rack.response_finished", Qnil);
|
@@ -969,6 +971,7 @@ void Init_up_ext(void) {
|
|
969
971
|
at_member_id = rb_intern("@member_id");
|
970
972
|
at_members = rb_intern("@members");
|
971
973
|
at_open = rb_intern("@open");
|
974
|
+
at_port = rb_intern("@port");
|
972
975
|
at_protocol = rb_intern("@protocol");
|
973
976
|
at_secret = rb_intern("@secret");
|
974
977
|
at_server = rb_intern("@server");
|
data/lib/up/bun/server.rb
CHANGED
@@ -27,7 +27,6 @@ module Up
|
|
27
27
|
@default_input = StringIO.new('', 'r')
|
28
28
|
@server = nil
|
29
29
|
@logger = logger
|
30
|
-
@t_factory = proc { |filename, _content_type| File.new(filename, 'a+') }
|
31
30
|
end
|
32
31
|
|
33
32
|
%x{
|
@@ -78,8 +77,6 @@ module Up
|
|
78
77
|
env.set('rack.input', #@default_input);
|
79
78
|
}
|
80
79
|
env.set('rack.logger', #@logger);
|
81
|
-
env.set('rack.multipart.buffer_size', 4096);
|
82
|
-
env.set('rack.multipart.tempfile_factory', #@t_factory);
|
83
80
|
if (upgrade) {
|
84
81
|
env.set('rack.upgrade?', #{:websocket});
|
85
82
|
}
|
@@ -92,7 +89,14 @@ module Up
|
|
92
89
|
env.set('QUERY_STRING', "");
|
93
90
|
env.set('REQUEST_METHOD', req.method);
|
94
91
|
env.set('PATH_INFO', req.url);
|
95
|
-
req.headers.forEach((k, v) => {
|
92
|
+
req.headers.forEach((k, v) => {
|
93
|
+
let h = k.toUpperCase().replaceAll('-', '_');
|
94
|
+
if (h[0] === 'C' && (h === 'CONTENT_TYPE || h === 'CONTENT_LENGTH')) {
|
95
|
+
env.set(h, v) ;
|
96
|
+
} else {
|
97
|
+
env.set('HTTP_' + h, v) ;
|
98
|
+
}
|
99
|
+
});
|
96
100
|
const rack_res = #@app.$call(env);
|
97
101
|
if (upgrade) {
|
98
102
|
const handler = env.get('rack.upgrade');
|
data/lib/up/ruby/cluster.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
# backtick_javascript: true
|
2
2
|
require 'etc'
|
3
3
|
require 'random/formatter'
|
4
|
+
require 'socket'
|
4
5
|
require 'up_ext'
|
5
6
|
|
6
7
|
module Up
|
@@ -38,8 +39,10 @@ module Up
|
|
38
39
|
|
39
40
|
def install_signal_handlers
|
40
41
|
Signal.trap('CHLD') do
|
41
|
-
|
42
|
-
|
42
|
+
unless members_alive?
|
43
|
+
warn "\nError: a cluster worker died!"
|
44
|
+
kill_members
|
45
|
+
end
|
43
46
|
end
|
44
47
|
Signal.trap('INT') do
|
45
48
|
warn "\nReceived CTRL-C!"
|
@@ -49,7 +52,7 @@ module Up
|
|
49
52
|
|
50
53
|
def kill_members
|
51
54
|
Signal.trap('CHLD', 'IGNORE')
|
52
|
-
STDERR.print "Stopping workers: "
|
55
|
+
STDERR.print "Stopping all workers: "
|
53
56
|
@members.each do |mid|
|
54
57
|
Process.kill('INT', mid) rescue nil
|
55
58
|
STDERR.print '.'
|
@@ -58,6 +61,15 @@ module Up
|
|
58
61
|
warn "\nCluster stopped."
|
59
62
|
Signal.trap('CHLD', 'DEFAULT')
|
60
63
|
end
|
64
|
+
|
65
|
+
def members_alive?
|
66
|
+
@workers.times do |i|
|
67
|
+
TCPSocket.new('localhost', @port + i + 1).close
|
68
|
+
end
|
69
|
+
true
|
70
|
+
rescue Errno::ECONNREFUSED, Errno::EADDRNOTAVAIL
|
71
|
+
false
|
72
|
+
end
|
61
73
|
end
|
62
74
|
end
|
63
75
|
end
|
@@ -33,7 +33,6 @@ module Up
|
|
33
33
|
@default_input = StringIO.new('', 'r')
|
34
34
|
@server = nil
|
35
35
|
@logger = logger
|
36
|
-
@t_factory = proc { |filename, _content_type| File.new(filename, 'a+') }
|
37
36
|
end
|
38
37
|
|
39
38
|
%x{
|
@@ -64,8 +63,6 @@ module Up
|
|
64
63
|
env.set('rack.errors',#{STDERR});
|
65
64
|
env.set('rack.input', ins.default_input);
|
66
65
|
env.set('rack.logger', ins.logger);
|
67
|
-
env.set('rack.multipart.buffer_size', 4096);
|
68
|
-
env.set('rack.multipart.tempfile_factory', ins.t_factory);
|
69
66
|
env.set('rack.url_scheme', ins.scheme);
|
70
67
|
env.set('SCRIPT_NAME', "");
|
71
68
|
env.set('SERVER_PROTOCOL', 'HTTP/1.1');
|
@@ -75,7 +72,14 @@ module Up
|
|
75
72
|
env.set('QUERY_STRING', req.getQuery() || '');
|
76
73
|
env.set('REQUEST_METHOD', req.getMethod().toUpperCase());
|
77
74
|
env.set('PATH_INFO', req.getUrl());
|
78
|
-
req.forEach((k, v) => {
|
75
|
+
req.forEach((k, v) => {
|
76
|
+
let h = k.toUpperCase().replaceAll('-', '_');
|
77
|
+
if (h[0] === 'C' && (h === 'CONTENT_TYPE || h === 'CONTENT_LENGTH')) {
|
78
|
+
env.set(h, v) ;
|
79
|
+
} else {
|
80
|
+
env.set('HTTP_' + h, v) ;
|
81
|
+
}
|
82
|
+
});
|
79
83
|
return env;
|
80
84
|
}
|
81
85
|
}
|
data/lib/up/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: opal-up
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jan Biedermann
|
@@ -162,7 +162,6 @@ files:
|
|
162
162
|
- ext/up_ext/loop_data.h
|
163
163
|
- ext/up_ext/socket.c
|
164
164
|
- ext/up_ext/up_ext.c
|
165
|
-
- lib/up/bun/rack_env.rb
|
166
165
|
- lib/up/bun/rack_server.rb
|
167
166
|
- lib/up/bun/server.rb
|
168
167
|
- lib/up/bun/server_cli.rb
|
data/lib/up/bun/rack_env.rb
DELETED
@@ -1,92 +0,0 @@
|
|
1
|
-
# backtick_javascript: true
|
2
|
-
|
3
|
-
require 'logger'
|
4
|
-
require 'up/version'
|
5
|
-
|
6
|
-
module Up
|
7
|
-
module Bun
|
8
|
-
class RackEnv < ::Hash
|
9
|
-
RACK_VARS = %w[rack.errors rack.hijack rack.hijack? rack.input rack.logger
|
10
|
-
rack.multipart.buffer_size rack.multipart.tempfile_factory
|
11
|
-
rack.response_finished
|
12
|
-
rack.session rack.upgrade rack.upgrade? rack.url_scheme
|
13
|
-
HTTP_ACCEPT HTTP_ACCEPT_ENCODING HTTP_ACCEPT_LANGUAGE
|
14
|
-
HTTP_CONNECTION HTTP_HOST HTTP_USER_AGENT PATH_INFO QUERY_STRING REQUEST_METHOD
|
15
|
-
SCRIPT_NAME SERVER_NAME SERVER_PROTOCOL SERVER_SOFTWARE]
|
16
|
-
def initialize(req, config)
|
17
|
-
@req = req
|
18
|
-
@config = config
|
19
|
-
end
|
20
|
-
|
21
|
-
def [](key)
|
22
|
-
return super(key) if key?(key)
|
23
|
-
self[key] = case key
|
24
|
-
when 'rack.errors'
|
25
|
-
STDERR
|
26
|
-
when 'rack.logger'
|
27
|
-
@config[:logger]
|
28
|
-
when 'rack.multipart.buffer_size'
|
29
|
-
4096
|
30
|
-
when 'rack.multipart.tempfile_factory'
|
31
|
-
proc { |_filename, _content_type| File.new }
|
32
|
-
when 'rack.session'
|
33
|
-
{}
|
34
|
-
when 'rack.url_scheme'
|
35
|
-
@config[:scheme]
|
36
|
-
when 'PATH_INFO'
|
37
|
-
`#@req.url`
|
38
|
-
when 'QUERY_STRING'
|
39
|
-
""
|
40
|
-
when 'RACK_ERRORS'
|
41
|
-
self['rack.errors']
|
42
|
-
when 'RACK_LOGGER'
|
43
|
-
self['rack.logger']
|
44
|
-
when 'REQUEST_METHOD'
|
45
|
-
`#@req.method`
|
46
|
-
when 'SCRIPT_NAME'
|
47
|
-
""
|
48
|
-
when 'SERVER_NAME'
|
49
|
-
@config[:host]
|
50
|
-
when 'SERVER_PORT'
|
51
|
-
@config[:port].to_s
|
52
|
-
when 'SERVER_PROTOCOL'
|
53
|
-
""
|
54
|
-
when 'SERVER_SOFTWARE'
|
55
|
-
"#{@config[:handler]}/#{Up::VERSION} #{@config[:engine]}"
|
56
|
-
else
|
57
|
-
if key.start_with?('HTTP_')
|
58
|
-
key = key[5..].gsub(/_/, '-')
|
59
|
-
`#@req.headers.get(key.toLowerCase())`
|
60
|
-
else
|
61
|
-
nil
|
62
|
-
end
|
63
|
-
end
|
64
|
-
end
|
65
|
-
|
66
|
-
def req_headers
|
67
|
-
h = {}
|
68
|
-
%x{
|
69
|
-
var hdr, hds = #@req.headers;
|
70
|
-
for (hdr of hds) { h.set(hdr[0], hdr[1]); }
|
71
|
-
}
|
72
|
-
h
|
73
|
-
end
|
74
|
-
|
75
|
-
def each
|
76
|
-
unless @got_them_all
|
77
|
-
RACK_VARS.each { |k| self[k] unless self.key?(k) }
|
78
|
-
@got_them_all = true
|
79
|
-
end
|
80
|
-
super
|
81
|
-
end
|
82
|
-
|
83
|
-
def to_s
|
84
|
-
unless @got_them_all
|
85
|
-
RACK_VARS.each { |k| self[k] unless self.key?(k) }
|
86
|
-
@got_them_all = true
|
87
|
-
end
|
88
|
-
super
|
89
|
-
end
|
90
|
-
end
|
91
|
-
end
|
92
|
-
end
|