unicorn-camilo 4.8.2.5.19 → 5.0.0
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/.document +0 -1
- data/.gitignore +2 -2
- data/{.wrongdoc.yml → .olddoc.yml} +7 -2
- data/Documentation/unicorn.1.txt +9 -2
- data/Documentation/unicorn_rails.1.txt +2 -2
- data/FAQ +9 -1
- data/GIT-VERSION-GEN +1 -1
- data/GNUmakefile +31 -46
- data/HACKING +13 -27
- data/ISSUES +80 -16
- data/KNOWN_ISSUES +10 -10
- data/Links +10 -7
- data/PHILOSOPHY +1 -1
- data/README +8 -13
- data/Rakefile +0 -44
- data/Sandbox +1 -1
- data/TUNING +6 -3
- data/archive/.gitignore +3 -0
- data/archive/slrnpull.conf +4 -0
- data/bin/unicorn +1 -1
- data/bin/unicorn_rails +1 -1
- data/examples/unicorn.conf.rb +11 -0
- data/ext/unicorn_http/httpdate.c +1 -1
- data/ext/unicorn_http/unicorn_http.rl +48 -150
- data/lib/unicorn.rb +9 -15
- data/lib/unicorn/configurator.rb +3 -20
- data/lib/unicorn/const.rb +2 -25
- data/lib/unicorn/http_request.rb +4 -1
- data/lib/unicorn/http_response.rb +1 -3
- data/lib/unicorn/http_server.rb +85 -86
- data/lib/unicorn/socket_helper.rb +33 -67
- data/lib/unicorn/tee_input.rb +8 -1
- data/lib/unicorn/tmpio.rb +2 -4
- data/lib/unicorn/util.rb +1 -0
- data/lib/unicorn/worker.rb +1 -13
- data/t/GNUmakefile +1 -5
- data/t/README +1 -1
- data/t/t0002-parser-error.sh +3 -3
- data/test/exec/test_exec.rb +1 -1
- data/test/test_helper.rb +2 -2
- data/test/unit/test_http_parser.rb +3 -3
- data/test/unit/test_http_parser_ng.rb +8 -117
- data/test/unit/test_request.rb +1 -1
- data/test/unit/test_response.rb +3 -9
- data/test/unit/test_server.rb +3 -3
- data/test/unit/test_signals.rb +1 -1
- data/test/unit/test_socket_helper.rb +5 -5
- data/test/unit/test_tee_input.rb +10 -0
- data/test/unit/test_upload.rb +1 -1
- data/test/unit/test_util.rb +1 -1
- data/unicorn.gemspec +7 -10
- metadata +15 -33
- data/examples/git.ru +0 -13
- data/lib/unicorn/app/exec_cgi.rb +0 -154
- data/lib/unicorn/app/inetd.rb +0 -109
- data/lib/unicorn/ssl_client.rb +0 -11
- data/lib/unicorn/ssl_configurator.rb +0 -104
- data/lib/unicorn/ssl_server.rb +0 -42
- data/local.mk.sample +0 -59
- data/script/isolate_for_tests +0 -31
- data/t/t0016-trust-x-forwarded-false.sh +0 -30
- data/t/t0017-trust-x-forwarded-true.sh +0 -30
- data/test/unit/test_http_parser_xftrust.rb +0 -38
- data/test/unit/test_sni_hostnames.rb +0 -47
data/KNOWN_ISSUES
CHANGED
@@ -17,16 +17,6 @@ acceptable solution. Those issues are documented here.
|
|
17
17
|
have builtin workarounds for Kernel#rand and OpenSSL::Random users,
|
18
18
|
but applications may use other PRNGs.
|
19
19
|
|
20
|
-
* Under some versions of Ruby 1.8, it is necessary to call +srand+ in an
|
21
|
-
after_fork hook to get correct random number generation. We have a builtin
|
22
|
-
workaround for this starting with \Unicorn 3.6.1
|
23
|
-
|
24
|
-
See http://redmine.ruby-lang.org/issues/show/4338
|
25
|
-
|
26
|
-
* On Ruby 1.8 prior to Ruby 1.8.7-p248, *BSD platforms have a broken
|
27
|
-
stdio that causes failure for file uploads larger than 112K. Upgrade
|
28
|
-
your version of Ruby or continue using Unicorn 1.x/3.4.x.
|
29
|
-
|
30
20
|
* For notes on sandboxing tools such as Bundler or Isolate,
|
31
21
|
see the {Sandbox}[link:Sandbox.html] page.
|
32
22
|
|
@@ -44,6 +34,16 @@ acceptable solution. Those issues are documented here.
|
|
44
34
|
|
45
35
|
== Known Issues (Old)
|
46
36
|
|
37
|
+
* Under some versions of Ruby 1.8, it is necessary to call +srand+ in an
|
38
|
+
after_fork hook to get correct random number generation. We have a builtin
|
39
|
+
workaround for this starting with \Unicorn 3.6.1
|
40
|
+
|
41
|
+
See http://redmine.ruby-lang.org/issues/show/4338
|
42
|
+
|
43
|
+
* On Ruby 1.8 prior to Ruby 1.8.7-p248, *BSD platforms have a broken
|
44
|
+
stdio that causes failure for file uploads larger than 112K. Upgrade
|
45
|
+
your version of Ruby or continue using Unicorn 1.x/3.4.x.
|
46
|
+
|
47
47
|
* Under Ruby 1.9.1, methods like Array#shuffle and Array#sample will
|
48
48
|
segfault if called after forking. Upgrade to Ruby 1.9.2 or call
|
49
49
|
"Kernel.rand" in your after_fork hook to reinitialize the random
|
data/Links
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
If you're interested in \Unicorn, you may be interested in some of the projects
|
4
4
|
listed below. If you have any links to add/change/remove, please tell us at
|
5
|
-
mailto:
|
5
|
+
mailto:unicorn-public@bogomips.org!
|
6
6
|
|
7
7
|
== Disclaimer
|
8
8
|
|
@@ -31,10 +31,10 @@ or services behind them.
|
|
31
31
|
|
32
32
|
=== \Unicorn is written to work with
|
33
33
|
|
34
|
-
* {Rack}[http://rack.
|
34
|
+
* {Rack}[http://rack.github.io/] - a minimal interface between webservers
|
35
35
|
supporting Ruby and Ruby frameworks
|
36
36
|
|
37
|
-
* {Ruby}[http://ruby-lang.org/] - the programming language of Rack and \Unicorn
|
37
|
+
* {Ruby}[http://www.ruby-lang.org/] - the programming language of Rack and \Unicorn
|
38
38
|
|
39
39
|
* {nginx}[http://nginx.org/] - the reverse proxy for use with \Unicorn
|
40
40
|
|
@@ -44,13 +44,16 @@ or services behind them.
|
|
44
44
|
|
45
45
|
* {Green Unicorn}[http://gunicorn.org/] - a Python version of \Unicorn
|
46
46
|
|
47
|
-
* {Rainbows!}[http://rainbows.
|
48
|
-
apps and slow clients.
|
47
|
+
* {Rainbows!}[http://rainbows.bogomips.org/] - \Unicorn for sleepy
|
48
|
+
apps and slow clients (historical).
|
49
|
+
|
50
|
+
* {yahns}[http://yahns.yhbt.net/] - like Rainbows!, but with fewer options
|
51
|
+
and designed for energy efficiency on idle sites.
|
49
52
|
|
50
53
|
=== Prior Work
|
51
54
|
|
52
|
-
* {Mongrel}[http://
|
53
|
-
based on
|
55
|
+
* {Mongrel}[http://rubygems.org/gems/mongrel] - the awesome webserver
|
56
|
+
unicorn is based on
|
54
57
|
|
55
58
|
* {david}[http://bogomips.org/david.git] - a tool to explain why you need
|
56
59
|
nginx in front of \Unicorn
|
data/PHILOSOPHY
CHANGED
@@ -138,7 +138,7 @@ where the HTTP connection spends a large amount of time idle.
|
|
138
138
|
Nevertheless, the ease of troubleshooting, debugging, and management of
|
139
139
|
unicorn may still outweigh the drawbacks for these applications.
|
140
140
|
|
141
|
-
The {Rainbows!}[http://rainbows.
|
141
|
+
The {Rainbows!}[http://rainbows.bogomips.org/] aims to fill the gap for
|
142
142
|
odd corner cases where the nginx + unicorn combination is not enough.
|
143
143
|
While Rainbows! management/administration is largely identical to
|
144
144
|
unicorn, Rainbows! is far more ambitious and has seen little real-world
|
data/README
CHANGED
@@ -10,9 +10,10 @@ both the the request and response in between \Unicorn and slow clients.
|
|
10
10
|
|
11
11
|
* Designed for Rack, Unix, fast clients, and ease-of-debugging. We
|
12
12
|
cut out everything that is better supported by the operating system,
|
13
|
-
{nginx}[http://nginx.net/] or {Rack}[http://rack.
|
13
|
+
{nginx}[http://nginx.net/] or {Rack}[http://rack.github.io/].
|
14
14
|
|
15
|
-
* Compatible with
|
15
|
+
* Compatible with Ruby 1.9.3 and later.
|
16
|
+
unicorn 4.8.x will remain supported for Ruby 1.8 users.
|
16
17
|
|
17
18
|
* Process management: \Unicorn will reap and restart workers that
|
18
19
|
die from broken apps. There is no need to manage multiple processes
|
@@ -74,12 +75,7 @@ See the included LICENSE file for details.
|
|
74
75
|
The library consists of a C extension so you'll need a C compiler
|
75
76
|
and Ruby development libraries/headers.
|
76
77
|
|
77
|
-
You may
|
78
|
-
and run setup.rb after unpacking it:
|
79
|
-
|
80
|
-
http://rubyforge.org/frs/?group_id=1306
|
81
|
-
|
82
|
-
You may also install it via RubyGems on RubyGems.org:
|
78
|
+
You may install it via RubyGems on RubyGems.org:
|
83
79
|
|
84
80
|
gem install unicorn
|
85
81
|
|
@@ -100,13 +96,13 @@ from git.
|
|
100
96
|
|
101
97
|
== Usage
|
102
98
|
|
103
|
-
===
|
99
|
+
=== Rack (including Rails 3+) applications
|
104
100
|
|
105
101
|
In APP_ROOT, run:
|
106
102
|
|
107
103
|
unicorn
|
108
104
|
|
109
|
-
===
|
105
|
+
=== Ancient Rails 1.2 - 2.x versions
|
110
106
|
|
111
107
|
In RAILS_ROOT, run:
|
112
108
|
|
@@ -127,8 +123,7 @@ The default settings are designed for maximum out-of-the-box
|
|
127
123
|
compatibility with existing applications.
|
128
124
|
|
129
125
|
Most command-line options for other Rack applications (above) are also
|
130
|
-
supported. Run `unicorn -h`
|
131
|
-
options.
|
126
|
+
supported. Run `unicorn -h` to see command-line options.
|
132
127
|
|
133
128
|
== Disclaimer
|
134
129
|
|
@@ -143,7 +138,7 @@ regarding this.
|
|
143
138
|
|
144
139
|
All feedback (bug reports, user/development dicussion, patches, pull
|
145
140
|
requests) go to the mailing list/newsgroup. See the ISSUES document for
|
146
|
-
information on the {mailing list}[mailto:
|
141
|
+
information on the {mailing list}[mailto:unicorn-public@bogomips.org].
|
147
142
|
|
148
143
|
For the latest on \Unicorn releases, you may also finger us at
|
149
144
|
unicorn@bogomips.org or check our NEWS page (and subscribe to our Atom
|
data/Rakefile
CHANGED
@@ -1,47 +1,3 @@
|
|
1
|
-
# -*- encoding: binary -*-
|
2
|
-
autoload :Gem, 'rubygems'
|
3
|
-
require 'wrongdoc'
|
4
|
-
|
5
|
-
cgit_url = Wrongdoc.config[:cgit_url]
|
6
|
-
git_url = Wrongdoc.config[:git_url]
|
7
|
-
|
8
|
-
desc "post to FM"
|
9
|
-
task :fm_update do
|
10
|
-
require 'tempfile'
|
11
|
-
require 'net/http'
|
12
|
-
require 'net/netrc'
|
13
|
-
require 'json'
|
14
|
-
version = ENV['VERSION'] or abort "VERSION= needed"
|
15
|
-
uri = URI.parse('https://freecode.com/projects/unicorn/releases.json')
|
16
|
-
rc = Net::Netrc.locate('unicorn-fm') or abort "~/.netrc not found"
|
17
|
-
api_token = rc.password
|
18
|
-
_, subject, body = `git cat-file tag v#{version}`.split(/\n\n/, 3)
|
19
|
-
tmp = Tempfile.new('fm-changelog')
|
20
|
-
tmp.puts subject
|
21
|
-
tmp.puts
|
22
|
-
tmp.puts body
|
23
|
-
tmp.flush
|
24
|
-
system(ENV["VISUAL"], tmp.path) or abort "#{ENV["VISUAL"]} failed: #$?"
|
25
|
-
changelog = File.read(tmp.path).strip
|
26
|
-
|
27
|
-
req = {
|
28
|
-
"auth_code" => api_token,
|
29
|
-
"release" => {
|
30
|
-
"tag_list" => "Experimental",
|
31
|
-
"version" => version,
|
32
|
-
"changelog" => changelog,
|
33
|
-
},
|
34
|
-
}.to_json
|
35
|
-
|
36
|
-
if ! changelog.strip.empty? && version =~ %r{\A[\d\.]+\d+\z}
|
37
|
-
Net::HTTP.start(uri.host, uri.port, :use_ssl => true) do |http|
|
38
|
-
p http.post(uri.path, req, {'Content-Type'=>'application/json'})
|
39
|
-
end
|
40
|
-
else
|
41
|
-
warn "not updating freshmeat for v#{version}"
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
1
|
# optional rake-compiler support in case somebody needs to cross compile
|
46
2
|
begin
|
47
3
|
mk = "ext/unicorn_http/Makefile"
|
data/Sandbox
CHANGED
@@ -86,7 +86,7 @@ For now workarounds include doing one of the following:
|
|
86
86
|
|
87
87
|
3. Explicitly setting RUBYLIB or $LOAD_PATH to include any gem path
|
88
88
|
where the unicorn gem is installed
|
89
|
-
(e.g. /usr/lib/ruby/gems/1.9.
|
89
|
+
(e.g. /usr/lib/ruby/gems/1.9.3/gems/unicorn-VERSION/lib)
|
90
90
|
|
91
91
|
=== RUBYOPT pollution from SIGUSR2 upgrades
|
92
92
|
|
data/TUNING
CHANGED
@@ -17,9 +17,12 @@ See Unicorn::Configurator for details on the config file format.
|
|
17
17
|
\Unicorn is NOT for serving slow clients, that is the job of nginx.
|
18
18
|
|
19
19
|
* worker_processes should be *at* *least* the number of CPU cores on
|
20
|
-
a dedicated server
|
21
|
-
responses that are /not/
|
22
|
-
workaround those inefficiencies.
|
20
|
+
a dedicated server (unless you do not have enough memory).
|
21
|
+
If your application has occasionally slow responses that are /not/
|
22
|
+
CPU-intensive, you may increase this to workaround those inefficiencies.
|
23
|
+
|
24
|
+
* Under Ruby 2.2 or later, Etc.nprocessors may be used to determine
|
25
|
+
the number of CPU cores present.
|
23
26
|
|
24
27
|
* worker_processes may be increased for Unicorn::OobGC users to provide
|
25
28
|
more consistent response times.
|
data/archive/.gitignore
ADDED
data/bin/unicorn
CHANGED
@@ -29,7 +29,7 @@ op = OptionParser.new("", 24, ' ') do |opts|
|
|
29
29
|
|
30
30
|
opts.on("-I", "--include PATH",
|
31
31
|
"specify $LOAD_PATH (may be used more than once)") do |path|
|
32
|
-
$LOAD_PATH.unshift(*path.split(
|
32
|
+
$LOAD_PATH.unshift(*path.split(':'))
|
33
33
|
end
|
34
34
|
|
35
35
|
opts.on("-r", "--require LIBRARY",
|
data/bin/unicorn_rails
CHANGED
@@ -30,7 +30,7 @@ op = OptionParser.new("", 24, ' ') do |opts|
|
|
30
30
|
|
31
31
|
opts.on("-I", "--include PATH",
|
32
32
|
"specify $LOAD_PATH (may be used more than once)") do |path|
|
33
|
-
$LOAD_PATH.unshift(*path.split(
|
33
|
+
$LOAD_PATH.unshift(*path.split(':'))
|
34
34
|
end
|
35
35
|
|
36
36
|
opts.on("-r", "--require LIBRARY",
|
data/examples/unicorn.conf.rb
CHANGED
@@ -54,12 +54,23 @@ GC.respond_to?(:copy_on_write_friendly=) and
|
|
54
54
|
# fast LAN.
|
55
55
|
check_client_connection false
|
56
56
|
|
57
|
+
# local variable to guard against running a hook multiple times
|
58
|
+
run_once = true
|
59
|
+
|
57
60
|
before_fork do |server, worker|
|
58
61
|
# the following is highly recomended for Rails + "preload_app true"
|
59
62
|
# as there's no need for the master process to hold a connection
|
60
63
|
defined?(ActiveRecord::Base) and
|
61
64
|
ActiveRecord::Base.connection.disconnect!
|
62
65
|
|
66
|
+
# Occasionally, it may be necessary to run non-idempotent code in the
|
67
|
+
# master before forking. Keep in mind the above disconnect! example
|
68
|
+
# is idempotent and does not need a guard.
|
69
|
+
if run_once
|
70
|
+
# do_something_once_here ...
|
71
|
+
run_once = false # prevent from firing again
|
72
|
+
end
|
73
|
+
|
63
74
|
# The following is only recommended for memory/DB-constrained
|
64
75
|
# installations. It is not needed if your system can house
|
65
76
|
# twice as many worker_processes as you have configured.
|
data/ext/unicorn_http/httpdate.c
CHANGED
@@ -66,7 +66,7 @@ static VALUE httpdate(VALUE self)
|
|
66
66
|
|
67
67
|
void init_unicorn_httpdate(void)
|
68
68
|
{
|
69
|
-
VALUE mod =
|
69
|
+
VALUE mod = rb_define_module("Unicorn");
|
70
70
|
mod = rb_define_module_under(mod, "HttpResponse");
|
71
71
|
|
72
72
|
buf = rb_str_new(0, buf_capa - 1);
|
@@ -29,82 +29,27 @@ void init_unicorn_httpdate(void);
|
|
29
29
|
/* all of these flags need to be set for keepalive to be supported */
|
30
30
|
#define UH_FL_KEEPALIVE (UH_FL_KAVERSION | UH_FL_REQEOF | UH_FL_HASHEADER)
|
31
31
|
|
32
|
-
/*
|
33
|
-
* whether or not to trust X-Forwarded-Proto and X-Forwarded-SSL when
|
34
|
-
* setting rack.url_scheme
|
35
|
-
*/
|
36
|
-
static VALUE trust_x_forward = Qtrue;
|
37
|
-
|
38
|
-
static unsigned long keepalive_requests = 100; /* same as nginx */
|
39
|
-
|
40
|
-
/*
|
41
|
-
* Returns the maximum number of keepalive requests a client may make
|
42
|
-
* before the parser refuses to continue.
|
43
|
-
*/
|
44
|
-
static VALUE ka_req(VALUE self)
|
45
|
-
{
|
46
|
-
return ULONG2NUM(keepalive_requests);
|
47
|
-
}
|
48
|
-
|
49
|
-
/*
|
50
|
-
* Sets the maximum number of keepalive requests a client may make.
|
51
|
-
* A special value of +nil+ causes this to be the maximum value
|
52
|
-
* possible (this is architecture-dependent).
|
53
|
-
*/
|
54
|
-
static VALUE set_ka_req(VALUE self, VALUE val)
|
55
|
-
{
|
56
|
-
keepalive_requests = NIL_P(val) ? ULONG_MAX : NUM2ULONG(val);
|
57
|
-
|
58
|
-
return ka_req(self);
|
59
|
-
}
|
60
|
-
|
61
|
-
/*
|
62
|
-
* Sets whether or not the parser will trust X-Forwarded-Proto and
|
63
|
-
* X-Forwarded-SSL headers and set "rack.url_scheme" to "https" accordingly.
|
64
|
-
* Rainbows!/Zbatery installations facing untrusted clients directly
|
65
|
-
* should set this to +false+
|
66
|
-
*/
|
67
|
-
static VALUE set_xftrust(VALUE self, VALUE val)
|
68
|
-
{
|
69
|
-
if (Qtrue == val || Qfalse == val)
|
70
|
-
trust_x_forward = val;
|
71
|
-
else
|
72
|
-
rb_raise(rb_eTypeError, "must be true or false");
|
73
|
-
|
74
|
-
return val;
|
75
|
-
}
|
76
|
-
|
77
|
-
/*
|
78
|
-
* returns whether or not the parser will trust X-Forwarded-Proto and
|
79
|
-
* X-Forwarded-SSL headers and set "rack.url_scheme" to "https" accordingly
|
80
|
-
*/
|
81
|
-
static VALUE xftrust(VALUE self)
|
82
|
-
{
|
83
|
-
return trust_x_forward;
|
84
|
-
}
|
85
|
-
|
86
|
-
static size_t MAX_HEADER_LEN = 1024 * (80 + 32); /* same as Mongrel */
|
32
|
+
static unsigned int MAX_HEADER_LEN = 1024 * (80 + 32); /* same as Mongrel */
|
87
33
|
|
88
34
|
/* this is only intended for use with Rainbows! */
|
89
35
|
static VALUE set_maxhdrlen(VALUE self, VALUE len)
|
90
36
|
{
|
91
|
-
return
|
37
|
+
return UINT2NUM(MAX_HEADER_LEN = NUM2UINT(len));
|
92
38
|
}
|
93
39
|
|
94
40
|
/* keep this small for Rainbows! since every client has one */
|
95
41
|
struct http_parser {
|
96
42
|
int cs; /* Ragel internal state */
|
97
43
|
unsigned int flags;
|
98
|
-
unsigned
|
99
|
-
|
100
|
-
size_t offset;
|
44
|
+
unsigned int mark;
|
45
|
+
unsigned int offset;
|
101
46
|
union { /* these 2 fields don't nest */
|
102
|
-
|
103
|
-
|
47
|
+
unsigned int field;
|
48
|
+
unsigned int query;
|
104
49
|
} start;
|
105
50
|
union {
|
106
|
-
|
107
|
-
|
51
|
+
unsigned int field_len; /* only used during header processing */
|
52
|
+
unsigned int dest_offset; /* only used during body processing */
|
108
53
|
} s;
|
109
54
|
VALUE buf;
|
110
55
|
VALUE env;
|
@@ -124,13 +69,25 @@ static void parser_raise(VALUE klass, const char *msg)
|
|
124
69
|
VALUE exc = rb_exc_new2(klass, msg);
|
125
70
|
VALUE bt = rb_ary_new();
|
126
71
|
|
127
|
-
|
128
|
-
|
72
|
+
rb_funcall(exc, id_set_backtrace, 1, bt);
|
73
|
+
rb_exc_raise(exc);
|
74
|
+
}
|
75
|
+
|
76
|
+
static inline unsigned int ulong2uint(unsigned long n)
|
77
|
+
{
|
78
|
+
unsigned int i = (unsigned int)n;
|
79
|
+
|
80
|
+
if (sizeof(unsigned int) != sizeof(unsigned long)) {
|
81
|
+
if ((unsigned long)i != n) {
|
82
|
+
rb_raise(rb_eRangeError, "too large to be 32-bit uint: %lu", n);
|
83
|
+
}
|
84
|
+
}
|
85
|
+
return i;
|
129
86
|
}
|
130
87
|
|
131
88
|
#define REMAINING (unsigned long)(pe - p)
|
132
|
-
#define LEN(AT, FPC) (FPC - buffer - hp->AT)
|
133
|
-
#define MARK(M,FPC) (hp->M = (FPC) - buffer)
|
89
|
+
#define LEN(AT, FPC) (ulong2uint(FPC - buffer) - hp->AT)
|
90
|
+
#define MARK(M,FPC) (hp->M = ulong2uint((FPC) - buffer))
|
134
91
|
#define PTR_TO(F) (buffer + hp->F)
|
135
92
|
#define STR_NEW(M,FPC) rb_str_new(PTR_TO(M), LEN(M, FPC))
|
136
93
|
#define STRIPPED_STR_NEW(M,FPC) stripped_str_new(PTR_TO(M), LEN(M, FPC))
|
@@ -466,7 +423,7 @@ http_parser_execute(struct http_parser *hp, char *buffer, size_t len)
|
|
466
423
|
post_exec: /* "_out:" also goes here */
|
467
424
|
if (hp->cs != http_parser_error)
|
468
425
|
hp->cs = cs;
|
469
|
-
hp->offset = p - buffer;
|
426
|
+
hp->offset = ulong2uint(p - buffer);
|
470
427
|
|
471
428
|
assert(p <= pe && "buffer overflow after parsing execute");
|
472
429
|
assert(hp->offset <= len && "offset longer than length");
|
@@ -491,26 +448,29 @@ static void set_url_scheme(VALUE env, VALUE *server_port)
|
|
491
448
|
VALUE scheme = rb_hash_aref(env, g_rack_url_scheme);
|
492
449
|
|
493
450
|
if (NIL_P(scheme)) {
|
494
|
-
|
495
|
-
|
451
|
+
/*
|
452
|
+
* would anybody be horribly opposed to removing the X-Forwarded-SSL
|
453
|
+
* and X-Forwarded-Proto handling from this parser? We've had it
|
454
|
+
* forever and nobody has said anything against it, either.
|
455
|
+
* Anyways, please send comments to our public mailing list:
|
456
|
+
* unicorn-public@bogomips.org (no HTML mail, no subscription necessary)
|
457
|
+
*/
|
458
|
+
scheme = rb_hash_aref(env, g_http_x_forwarded_ssl);
|
459
|
+
if (!NIL_P(scheme) && STR_CSTR_EQ(scheme, "on")) {
|
460
|
+
*server_port = g_port_443;
|
461
|
+
scheme = g_https;
|
496
462
|
} else {
|
497
|
-
scheme = rb_hash_aref(env,
|
498
|
-
if (
|
499
|
-
|
500
|
-
scheme = g_https;
|
463
|
+
scheme = rb_hash_aref(env, g_http_x_forwarded_proto);
|
464
|
+
if (NIL_P(scheme)) {
|
465
|
+
scheme = g_http;
|
501
466
|
} else {
|
502
|
-
|
503
|
-
if (
|
504
|
-
|
467
|
+
long len = RSTRING_LEN(scheme);
|
468
|
+
if (len >= 5 && !memcmp(RSTRING_PTR(scheme), "https", 5)) {
|
469
|
+
if (len != 5)
|
470
|
+
scheme = g_https;
|
471
|
+
*server_port = g_port_443;
|
505
472
|
} else {
|
506
|
-
|
507
|
-
if (len >= 5 && !memcmp(RSTRING_PTR(scheme), "https", 5)) {
|
508
|
-
if (len != 5)
|
509
|
-
scheme = g_https;
|
510
|
-
*server_port = g_port_443;
|
511
|
-
} else {
|
512
|
-
scheme = g_http;
|
513
|
-
}
|
473
|
+
scheme = g_http;
|
514
474
|
}
|
515
475
|
}
|
516
476
|
}
|
@@ -608,7 +568,6 @@ static VALUE HttpParser_init(VALUE self)
|
|
608
568
|
http_parser_init(hp);
|
609
569
|
hp->buf = rb_str_new(NULL, 0);
|
610
570
|
hp->env = rb_hash_new();
|
611
|
-
hp->nr_requests = keepalive_requests;
|
612
571
|
|
613
572
|
return self;
|
614
573
|
}
|
@@ -631,55 +590,6 @@ static VALUE HttpParser_clear(VALUE self)
|
|
631
590
|
return self;
|
632
591
|
}
|
633
592
|
|
634
|
-
/**
|
635
|
-
* call-seq:
|
636
|
-
* parser.dechunk! => parser
|
637
|
-
*
|
638
|
-
* Resets the parser to a state suitable for dechunking response bodies
|
639
|
-
*
|
640
|
-
*/
|
641
|
-
static VALUE HttpParser_dechunk_bang(VALUE self)
|
642
|
-
{
|
643
|
-
struct http_parser *hp = data_get(self);
|
644
|
-
|
645
|
-
http_parser_init(hp);
|
646
|
-
|
647
|
-
/*
|
648
|
-
* we don't care about trailers in dechunk-only mode,
|
649
|
-
* but if we did we'd set UH_FL_HASTRAILER and clear hp->env
|
650
|
-
*/
|
651
|
-
if (0) {
|
652
|
-
rb_funcall(hp->env, id_clear, 0);
|
653
|
-
hp->flags = UH_FL_HASTRAILER;
|
654
|
-
}
|
655
|
-
|
656
|
-
hp->flags |= UH_FL_HASBODY | UH_FL_INBODY | UH_FL_CHUNKED;
|
657
|
-
hp->cs = http_parser_en_ChunkedBody;
|
658
|
-
|
659
|
-
return self;
|
660
|
-
}
|
661
|
-
|
662
|
-
/**
|
663
|
-
* call-seq:
|
664
|
-
* parser.reset => nil
|
665
|
-
*
|
666
|
-
* Resets the parser to it's initial state so that you can reuse it
|
667
|
-
* rather than making new ones.
|
668
|
-
*
|
669
|
-
* This method is deprecated and to be removed in Unicorn 4.x
|
670
|
-
*/
|
671
|
-
static VALUE HttpParser_reset(VALUE self)
|
672
|
-
{
|
673
|
-
static int warned;
|
674
|
-
|
675
|
-
if (!warned) {
|
676
|
-
rb_warn("Unicorn::HttpParser#reset is deprecated; "
|
677
|
-
"use Unicorn::HttpParser#clear instead");
|
678
|
-
}
|
679
|
-
HttpParser_clear(self);
|
680
|
-
return Qnil;
|
681
|
-
}
|
682
|
-
|
683
593
|
static void advance_str(VALUE str, off_t nr)
|
684
594
|
{
|
685
595
|
long len = RSTRING_LEN(str);
|
@@ -842,15 +752,13 @@ static VALUE HttpParser_keepalive(VALUE self)
|
|
842
752
|
* parser.next? => true or false
|
843
753
|
*
|
844
754
|
* Exactly like HttpParser#keepalive?, except it will reset the internal
|
845
|
-
* parser state on next parse if it returns true.
|
846
|
-
* the maximum *keepalive_requests* value and return false if that is
|
847
|
-
* reached.
|
755
|
+
* parser state on next parse if it returns true.
|
848
756
|
*/
|
849
757
|
static VALUE HttpParser_next(VALUE self)
|
850
758
|
{
|
851
759
|
struct http_parser *hp = data_get(self);
|
852
760
|
|
853
|
-
if (
|
761
|
+
if (HP_FL_ALL(hp, KEEPALIVE)) {
|
854
762
|
HP_FL_SET(hp, TO_CLEAR);
|
855
763
|
return Qtrue;
|
856
764
|
}
|
@@ -969,7 +877,7 @@ void Init_unicorn_http(void)
|
|
969
877
|
{
|
970
878
|
VALUE mUnicorn, cHttpParser;
|
971
879
|
|
972
|
-
mUnicorn =
|
880
|
+
mUnicorn = rb_define_module("Unicorn");
|
973
881
|
cHttpParser = rb_define_class_under(mUnicorn, "HttpParser", rb_cObject);
|
974
882
|
eHttpParserError =
|
975
883
|
rb_define_class_under(mUnicorn, "HttpParserError", rb_eIOError);
|
@@ -982,8 +890,6 @@ void Init_unicorn_http(void)
|
|
982
890
|
rb_define_alloc_func(cHttpParser, HttpParser_alloc);
|
983
891
|
rb_define_method(cHttpParser, "initialize", HttpParser_init, 0);
|
984
892
|
rb_define_method(cHttpParser, "clear", HttpParser_clear, 0);
|
985
|
-
rb_define_method(cHttpParser, "reset", HttpParser_reset, 0);
|
986
|
-
rb_define_method(cHttpParser, "dechunk!", HttpParser_dechunk_bang, 0);
|
987
893
|
rb_define_method(cHttpParser, "parse", HttpParser_parse, 0);
|
988
894
|
rb_define_method(cHttpParser, "add_parse", HttpParser_add_parse, 1);
|
989
895
|
rb_define_method(cHttpParser, "headers", HttpParser_headers, 2);
|
@@ -1012,14 +918,6 @@ void Init_unicorn_http(void)
|
|
1012
918
|
*/
|
1013
919
|
rb_define_const(cHttpParser, "LENGTH_MAX", OFFT2NUM(UH_OFF_T_MAX));
|
1014
920
|
|
1015
|
-
/* default value for keepalive_requests */
|
1016
|
-
rb_define_const(cHttpParser, "KEEPALIVE_REQUESTS_DEFAULT",
|
1017
|
-
ULONG2NUM(keepalive_requests));
|
1018
|
-
|
1019
|
-
rb_define_singleton_method(cHttpParser, "keepalive_requests", ka_req, 0);
|
1020
|
-
rb_define_singleton_method(cHttpParser, "keepalive_requests=", set_ka_req, 1);
|
1021
|
-
rb_define_singleton_method(cHttpParser, "trust_x_forwarded=", set_xftrust, 1);
|
1022
|
-
rb_define_singleton_method(cHttpParser, "trust_x_forwarded?", xftrust, 0);
|
1023
921
|
rb_define_singleton_method(cHttpParser, "max_header_len=", set_maxhdrlen, 1);
|
1024
922
|
|
1025
923
|
init_common_fields();
|