yahns 1.11.0 → 1.12.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (100) hide show
  1. checksums.yaml +4 -4
  2. data/.gitattributes +5 -0
  3. data/.gitignore +2 -2
  4. data/Documentation/.gitignore +5 -2
  5. data/Documentation/GNUmakefile +25 -6
  6. data/Documentation/yahns-rackup.pod +178 -0
  7. data/Documentation/yahns.pod +96 -0
  8. data/Documentation/yahns_config.pod +658 -0
  9. data/GIT-VERSION-GEN +6 -5
  10. data/GNUmakefile +3 -3
  11. data/HACKING +2 -2
  12. data/README +6 -6
  13. data/Rakefile +7 -2
  14. data/bin/yahns +3 -2
  15. data/bin/yahns-rackup +3 -2
  16. data/examples/yahns_rack_basic.conf.rb +7 -2
  17. data/extras/README +2 -2
  18. data/extras/autoindex.rb +3 -2
  19. data/extras/exec_cgi.rb +3 -2
  20. data/extras/proxy_pass.rb +6 -5
  21. data/extras/try_gzip_static.rb +4 -3
  22. data/lib/yahns.rb +15 -9
  23. data/lib/yahns/acceptor.rb +4 -3
  24. data/lib/yahns/cap_input.rb +2 -1
  25. data/lib/yahns/client_expire_generic.rb +3 -2
  26. data/lib/yahns/client_expire_tcpi.rb +3 -2
  27. data/lib/yahns/config.rb +23 -18
  28. data/lib/yahns/daemon.rb +3 -2
  29. data/lib/yahns/fdmap.rb +3 -2
  30. data/lib/yahns/http_client.rb +4 -7
  31. data/lib/yahns/http_context.rb +13 -10
  32. data/lib/yahns/http_response.rb +8 -5
  33. data/lib/yahns/log.rb +3 -2
  34. data/lib/yahns/max_body.rb +2 -1
  35. data/lib/yahns/max_body/rewindable_wrapper.rb +3 -2
  36. data/lib/yahns/max_body/wrapper.rb +10 -5
  37. data/lib/yahns/openssl_client.rb +3 -2
  38. data/lib/yahns/openssl_server.rb +3 -2
  39. data/lib/yahns/proxy_http_response.rb +8 -7
  40. data/lib/yahns/proxy_pass.rb +7 -5
  41. data/lib/yahns/queue.rb +3 -2
  42. data/lib/yahns/queue_egg.rb +3 -2
  43. data/lib/yahns/queue_epoll.rb +4 -3
  44. data/lib/yahns/queue_kqueue.rb +4 -3
  45. data/lib/yahns/queue_quitter.rb +3 -2
  46. data/lib/yahns/queue_quitter_pipe.rb +3 -2
  47. data/lib/yahns/rack.rb +5 -4
  48. data/lib/yahns/rackup_handler.rb +4 -2
  49. data/lib/yahns/sendfile_compat.rb +5 -8
  50. data/lib/yahns/server.rb +14 -3
  51. data/lib/yahns/server_mp.rb +4 -2
  52. data/lib/yahns/sigevent.rb +3 -2
  53. data/lib/yahns/sigevent_efd.rb +3 -2
  54. data/lib/yahns/sigevent_pipe.rb +3 -2
  55. data/lib/yahns/socket_helper.rb +4 -2
  56. data/lib/yahns/stream_file.rb +3 -2
  57. data/lib/yahns/stream_input.rb +5 -4
  58. data/lib/yahns/tcp_server.rb +3 -2
  59. data/lib/yahns/tee_input.rb +4 -2
  60. data/lib/yahns/tmpio.rb +2 -1
  61. data/lib/yahns/unix_server.rb +3 -2
  62. data/lib/yahns/wbuf.rb +3 -2
  63. data/lib/yahns/wbuf_common.rb +4 -2
  64. data/lib/yahns/wbuf_str.rb +3 -2
  65. data/lib/yahns/worker.rb +3 -2
  66. data/test/covshow.rb +3 -2
  67. data/test/helper.rb +3 -2
  68. data/test/server_helper.rb +3 -2
  69. data/test/test_bin.rb +3 -2
  70. data/test/test_buffer_tmpdir.rb +3 -2
  71. data/test/test_client_expire.rb +5 -4
  72. data/test/test_client_max_body_size.rb +4 -3
  73. data/test/test_config.rb +3 -2
  74. data/test/test_expect_100.rb +5 -4
  75. data/test/test_extras_autoindex.rb +3 -2
  76. data/test/test_extras_exec_cgi.rb +4 -3
  77. data/test/test_extras_exec_cgi.sh +2 -2
  78. data/test/test_extras_proxy_pass.rb +3 -2
  79. data/test/test_extras_try_gzip_static.rb +3 -2
  80. data/test/test_fdmap.rb +3 -2
  81. data/test/test_input.rb +4 -3
  82. data/test/test_mt_accept.rb +3 -2
  83. data/test/test_output_buffering.rb +4 -3
  84. data/test/test_proxy_pass.rb +15 -14
  85. data/test/test_rack.rb +3 -2
  86. data/test/test_rack_hijack.rb +3 -2
  87. data/test/test_reopen_logs.rb +3 -2
  88. data/test/test_response.rb +3 -2
  89. data/test/test_serve_static.rb +2 -2
  90. data/test/test_server.rb +15 -14
  91. data/test/test_ssl.rb +60 -9
  92. data/test/test_stream_file.rb +3 -2
  93. data/test/test_tmpio.rb +3 -2
  94. data/test/test_unix_socket.rb +3 -2
  95. data/test/test_wbuf.rb +3 -2
  96. data/yahns.gemspec +5 -2
  97. metadata +21 -6
  98. data/Documentation/yahns-rackup.txt +0 -152
  99. data/Documentation/yahns.txt +0 -72
  100. data/Documentation/yahns_config.txt +0 -584
@@ -1,12 +1,9 @@
1
1
  # -*- encoding: binary -*-
2
- # Copyright (C) 2013-2015 all contributors <yahns-public@yhbt.net>
3
- # License: GPLv3 or later (https://www.gnu.org/licenses/gpl-3.0.txt)
2
+ # Copyright (C) 2013-2016 all contributors <yahns-public@yhbt.net>
3
+ # License: GPL-3.0+ (https://www.gnu.org/licenses/gpl-3.0.txt)
4
+ # frozen_string_literal: true
4
5
  class Yahns::HttpClient < Kgio::Socket # :nodoc:
5
- NULL_IO = StringIO.new("")
6
-
7
- # FIXME: we shouldn't have this at all when we go Unicorn 5-only
8
- Unicorn::HttpParser.respond_to?(:keepalive_requests=) and
9
- Unicorn::HttpParser.keepalive_requests = 0xffffffff
6
+ NULL_IO = StringIO.new(''.dup) # :nodoc:
10
7
 
11
8
  include Yahns::HttpResponse
12
9
  QEV_FLAGS = Yahns::Queue::QEV_RD # used by acceptor
@@ -1,6 +1,7 @@
1
1
  # -*- encoding: binary -*-
2
- # Copyright (C) 2013-2015 all contributors <yahns-public@yhbt.net>
3
- # License: GPLv3 or later (https://www.gnu.org/licenses/gpl-3.0.txt)
2
+ # Copyright (C) 2013-2016 all contributors <yahns-public@yhbt.net>
3
+ # License: GPL-3.0+ (https://www.gnu.org/licenses/gpl-3.0.txt)
4
+ # frozen_string_literal: true
4
5
 
5
6
  # subclasses of Yahns::HttpClient will class extend this
6
7
 
@@ -16,7 +17,7 @@ module Yahns::HttpContext # :nodoc:
16
17
  attr_accessor :qegg
17
18
  attr_accessor :queue # set right before spawning acceptors
18
19
  attr_reader :app
19
- attr_reader :app_defaults
20
+ attr_accessor :app_defaults
20
21
  attr_writer :input_buffer_tmpdir
21
22
  attr_accessor :output_buffer_tmpdir
22
23
 
@@ -79,13 +80,15 @@ def errors
79
80
 
80
81
  def tmpio_for(len, env)
81
82
  # short requests are most common
82
- return StringIO.new('') if len && len <= @client_body_buffer_size;
83
-
84
- # too big or chunked, unknown length
85
- tmp = @input_buffer_tmpdir
86
- mbs = @client_max_body_size
87
- tmp = mbs ? Yahns::CapInput.new(mbs, tmp) : Yahns::TmpIO.new(tmp)
88
- (env['rack.tempfiles'] ||= []) << tmp
83
+ if len && len <= @client_body_buffer_size;
84
+ # Can't use binmode, yet: https://bugs.ruby-lang.org/issues/11945
85
+ tmp = StringIO.new(''.dup)
86
+ else # too big or chunked, unknown length
87
+ tmp = @input_buffer_tmpdir
88
+ mbs = @client_max_body_size
89
+ tmp = mbs ? Yahns::CapInput.new(mbs, tmp) : Yahns::TmpIO.new(tmp)
90
+ (env['rack.tempfiles'] ||= []) << tmp
91
+ end
89
92
  tmp
90
93
  end
91
94
  end
@@ -1,6 +1,7 @@
1
1
  # -*- encoding: binary -*-
2
- # Copyright (C) 2013-2015 all contributors <yahns-public@yhbt.net>
3
- # License: GPLv3 or later (https://www.gnu.org/licenses/gpl-3.0.txt)
2
+ # Copyright (C) 2013-2016 all contributors <yahns-public@yhbt.net>
3
+ # License: GPL-3.0+ (https://www.gnu.org/licenses/gpl-3.0.txt)
4
+ # frozen_string_literal: true
4
5
  require_relative 'stream_file'
5
6
  require_relative 'wbuf_str'
6
7
 
@@ -134,7 +135,7 @@ def http_response_write(status, headers, body)
134
135
  code = status.to_i
135
136
  msg = Rack::Utils::HTTP_STATUS_CODES[code]
136
137
  buf = "#{response_start}#{msg ? %Q(#{code} #{msg}) : status}\r\n" \
137
- "Date: #{httpdate}\r\n"
138
+ "Date: #{httpdate}\r\n".dup
138
139
  headers.each do |key, value|
139
140
  case key
140
141
  when %r{\ADate\z}i
@@ -161,11 +162,13 @@ def http_response_write(status, headers, body)
161
162
  : "Connection: close\r\n\r\n".freeze)
162
163
  case rv = kgio_syssend(buf, flags)
163
164
  when nil # all done, likely
165
+ buf.clear
166
+ buf = nil # recycle any memory we used ASAP
164
167
  break
165
168
  when String
166
169
  flags = MSG_DONTWAIT
167
- buf = rv # hope the skb grows
168
- when :wait_writable, :wait_readable
170
+ buf = rv # unlikely, hope the skb grows
171
+ when :wait_writable, :wait_readable # unlikely
169
172
  if k.output_buffering
170
173
  alive = hijack ? hijack : alive
171
174
  rv = response_header_blocked(rv, buf, body, alive, offset, count)
@@ -1,6 +1,7 @@
1
1
  # -*- encoding: binary -*-
2
- # Copyright (C) 2013-2015 all contributors <yahns-public@yhbt.net>
3
- # License: GPLv3 or later (https://www.gnu.org/licenses/gpl-3.0.txt)
2
+ # Copyright (C) 2013-2016 all contributors <yahns-public@yhbt.net>
3
+ # License: GPL-3.0+ (https://www.gnu.org/licenses/gpl-3.0.txt)
4
+ # frozen_string_literal: true
4
5
 
5
6
  # logging-related utility functions for all of yahns
6
7
  module Yahns::Log # :nodoc:
@@ -1,6 +1,7 @@
1
1
  # -*- encoding: binary -*-
2
- # Copyright (C) 2013-2015 all contributors <yahns-public@yhbt.net>
2
+ # Copyright (C) 2013-2016 all contributors <yahns-public@yhbt.net>
3
3
  # License: GPLv2 or later (https://www.gnu.org/licenses/gpl-2.0.txt)
4
+ # frozen_string_literal: true
4
5
 
5
6
  # Middleware used to enforce client_max_body_size for TeeInput users.
6
7
  #
@@ -1,6 +1,7 @@
1
1
  # -*- encoding: binary -*-
2
- # Copyright (C) 2013-2015 all contributors <yahns-public@yhbt.net>
2
+ # Copyright (C) 2013-2016 all contributors <yahns-public@yhbt.net>
3
3
  # License: GPLv2 or later (https://www.gnu.org/licenses/gpl-2.0.txt)
4
+ # frozen_string_literal: true
4
5
  class Yahns::MaxBody::RewindableWrapper < Yahns::MaxBody::Wrapper # :nodoc:
5
6
  def initialize(rack_input, limit)
6
7
  @orig_limit = limit
@@ -9,7 +10,7 @@ def initialize(rack_input, limit)
9
10
 
10
11
  def rewind
11
12
  @limit = @orig_limit
12
- @rbuf = ''
13
+ @rbuf = ''.dup
13
14
  @input.rewind
14
15
  end
15
16
 
@@ -1,11 +1,14 @@
1
1
  # -*- encoding: binary -*-
2
- # Copyright (C) 2013-2015 all contributors <yahns-public@yhbt.net>
2
+ # Copyright (C) 2013-2016 all contributors <yahns-public@yhbt.net>
3
3
  # License: GPLv2 or later (https://www.gnu.org/licenses/gpl-2.0.txt)
4
+ # frozen_string_literal: true
4
5
  #
5
6
  # This is only used for chunked request bodies, which are rare
6
7
  class Yahns::MaxBody::Wrapper # :nodoc:
7
8
  def initialize(rack_input, limit)
8
- @input, @limit, @rbuf = rack_input, limit, ''
9
+ @input = rack_input
10
+ @limit = limit
11
+ @rbuf = ''.dup
9
12
  end
10
13
 
11
14
  def each
@@ -16,7 +19,7 @@ def each
16
19
 
17
20
  # chunked encoding means this method behaves more like readpartial,
18
21
  # since Rack does not support a method named "readpartial"
19
- def read(length = nil, rv = '')
22
+ def read(length = nil, rv = ''.dup)
20
23
  if length
21
24
  if length <= @rbuf.size
22
25
  length < 0 and raise ArgumentError, "negative length #{length} given"
@@ -45,6 +48,7 @@ def gets
45
48
 
46
49
  if tmp = checked_read(16384)
47
50
  @rbuf << tmp
51
+ tmp.clear
48
52
  elsif @rbuf.empty? # EOF
49
53
  return nil
50
54
  else # EOF, return whatever is left
@@ -53,7 +57,7 @@ def gets
53
57
  end while true
54
58
  end
55
59
 
56
- def checked_read(length = 16384, buf = '')
60
+ def checked_read(length = 16384, buf = ''.dup)
57
61
  if @input.read(length, buf)
58
62
  throw :yahns_EFBIG if ((@limit -= buf.size) < 0)
59
63
  return buf
@@ -62,10 +66,11 @@ def checked_read(length = 16384, buf = '')
62
66
 
63
67
  def read_all
64
68
  rv = @rbuf.slice!(0, @rbuf.size)
65
- tmp = ''
69
+ tmp = ''.dup
66
70
  while checked_read(16384, tmp)
67
71
  rv << tmp
68
72
  end
73
+ tmp.clear
69
74
  rv
70
75
  end
71
76
  end
@@ -1,5 +1,6 @@
1
- # Copyright (C) 2014, all contributors <yahns-public@yhbt.net>
2
- # License: GPLv3 or later (see COPYING for details)
1
+ # Copyright (C) 2013-2016 all contributors <yahns-public@yhbt.net>
2
+ # License: GPL-3.0+ (https://www.gnu.org/licenses/gpl-3.0.txt)
3
+ # frozen_string_literal: true
3
4
 
4
5
  require_relative 'sendfile_compat'
5
6
 
@@ -1,5 +1,6 @@
1
- # Copyright (C) 2014, all contributors <yahns-public@yhbt.net>
2
- # License: GPLv3 or later (see COPYING for details)
1
+ # Copyright (C) 2013-2016 all contributors <yahns-public@yhbt.net>
2
+ # License: GPL-3.0+ (https://www.gnu.org/licenses/gpl-3.0.txt)
3
+ # frozen_string_literal: true
3
4
 
4
5
  require_relative 'acceptor'
5
6
  require_relative 'openssl_client'
@@ -1,6 +1,7 @@
1
1
  # -*- encoding: binary -*-
2
- # Copyright (C) 2015 all contributors <yahns-public@yhbt.net>
3
- # License: GPLv3 or later (https://www.gnu.org/licenses/gpl-3.0.txt)
2
+ # Copyright (C) 2015-2016 all contributors <yahns-public@yhbt.net>
3
+ # License: GPL-3.0+ (https://www.gnu.org/licenses/gpl-3.0.txt)
4
+ # frozen_string_literal: true
4
5
 
5
6
  # loaded by yahns/proxy_pass, this relies on Yahns::HttpResponse for
6
7
  # constants.
@@ -69,7 +70,7 @@ def proxy_response_start(res, tip, kcar, req_res)
69
70
  alive = @hs.next? && self.class.persistent_connections
70
71
  response_headers = env['yahns.proxy_pass.response_headers']
71
72
 
72
- res = "HTTP/1.1 #{msg ? %Q(#{code} #{msg}) : status}\r\n"
73
+ res = "HTTP/1.1 #{msg ? %Q(#{code} #{msg}) : status}\r\n".dup
73
74
  headers.each do |key,value| # n.b.: headers is an Array of 2-element Arrays
74
75
  case key
75
76
  when /\A(?:Connection|Keep-Alive)\z/i
@@ -123,7 +124,7 @@ def proxy_response_start(res, tip, kcar, req_res)
123
124
 
124
125
  elsif kcar.chunked? # nasty chunked body
125
126
  req_res.proxy_trailers = nil # define to avoid warnings for now
126
- buf = ''
127
+ buf = ''.dup
127
128
  case tmp = tip.shift || req_res.kgio_tryread(0x2000, rbuf)
128
129
  when String
129
130
  kcar.filter_body(buf, tmp)
@@ -136,7 +137,7 @@ def proxy_response_start(res, tip, kcar, req_res)
136
137
 
137
138
  buf = tmp
138
139
  req_res.proxy_trailers = [ buf, tlr = [] ]
139
- rbuf = Thread.current[:yahns_rbuf] = ''
140
+ rbuf = Thread.current[:yahns_rbuf] = ''.dup
140
141
  until kcar.trailers(tlr, buf)
141
142
  case rv = req_res.kgio_tryread(0x2000, rbuf)
142
143
  when String
@@ -186,7 +187,7 @@ def proxy_response_finish(kcar, wbuf, req_res)
186
187
  end while len != 0
187
188
 
188
189
  elsif kcar.chunked? # nasty chunked body
189
- buf = ''
190
+ buf = ''.dup
190
191
 
191
192
  unless req_res.proxy_trailers
192
193
  # are we done dechunking the main body, yet?
@@ -200,7 +201,7 @@ def proxy_response_finish(kcar, wbuf, req_res)
200
201
  return :wait_readable # self remains in :ignore, wait on upstream
201
202
  end until kcar.body_eof?
202
203
  req_res.proxy_trailers = [ tmp, [] ] # onto trailers!
203
- rbuf = Thread.current[:yahns_rbuf] = ''
204
+ rbuf = Thread.current[:yahns_rbuf] = ''.dup
204
205
  end
205
206
 
206
207
  buf, tlr = *req_res.proxy_trailers
@@ -1,6 +1,7 @@
1
1
  # -*- encoding: binary -*-
2
- # Copyright (C) 2013-2015 all contributors <yahns-public@yhbt.net>
3
- # License: GPLv3 or later (https://www.gnu.org/licenses/gpl-3.0.txt)
2
+ # Copyright (C) 2013-2016 all contributors <yahns-public@yhbt.net>
3
+ # License: GPL-3.0+ (https://www.gnu.org/licenses/gpl-3.0.txt)
4
+ # frozen_string_literal: true
4
5
  require 'socket'
5
6
  require 'kgio'
6
7
  require 'kcar' # gem install kcar
@@ -10,7 +11,7 @@
10
11
  require_relative 'proxy_http_response'
11
12
 
12
13
  class Yahns::ProxyPass # :nodoc:
13
- class ReqRes < Kgio::Socket
14
+ class ReqRes < Kgio::Socket # :nodoc:
14
15
  attr_writer :resbuf
15
16
  attr_accessor :proxy_trailers
16
17
 
@@ -24,7 +25,7 @@ def req_start(c, req, input, chunked)
24
25
  # we must reinitialize the thread-local rbuf if it may get beyond the
25
26
  # current thread
26
27
  def detach_rbuf!
27
- Thread.current[:yahns_rbuf] = ''
28
+ Thread.current[:yahns_rbuf] = ''.dup
28
29
  end
29
30
 
30
31
  def yahns_step # yahns event loop entry point
@@ -225,7 +226,8 @@ def call(env)
225
226
  end
226
227
 
227
228
  req = "#{env['REQUEST_METHOD']} #{req} #{ver}\r\n" \
228
- "X-Forwarded-For: #{env["REMOTE_ADDR"]}\r\n"
229
+ "X-Forwarded-Proto: #{env['rack.url_scheme']}\r\n" \
230
+ "X-Forwarded-For: #{env["REMOTE_ADDR"]}\r\n".dup
229
231
 
230
232
  # pass most HTTP_* headers through as-is
231
233
  chunked = false
@@ -1,5 +1,6 @@
1
- # Copyright (C) 2013-2014, all contributors
2
- # License: GPLv3 or later (https://www.gnu.org/licenses/gpl-3.0.txt)
1
+ # Copyright (C) 2013-2016 all contributors <yahns-public@yhbt.net>
2
+ # License: GPL-3.0+ (https://www.gnu.org/licenses/gpl-3.0.txt)
3
+ # frozen_string_literal: true
3
4
  if SleepyPenguin.const_defined?(:Epoll)
4
5
  require_relative 'queue_epoll'
5
6
  else
@@ -1,5 +1,6 @@
1
- # Copyright (C) 2013-2015 all contributors <yahns-public@yhbt.net>
2
- # License: GPLv3 or later (https://www.gnu.org/licenses/gpl-3.0.txt)
1
+ # Copyright (C) 2013-2016 all contributors <yahns-public@yhbt.net>
2
+ # License: GPL-3.0+ (https://www.gnu.org/licenses/gpl-3.0.txt)
3
+ # frozen_string_literal: true
3
4
 
4
5
  # this represents a Yahns::Queue before its vivified. This only
5
6
  # lives in the parent process and should be clobbered after qc_vivify
@@ -1,6 +1,7 @@
1
1
  # -*- encoding: binary -*-
2
- # Copyright (C) 2013-2015 all contributors <yahns-public@yhbt.net>
3
- # License: GPLv3 or later (https://www.gnu.org/licenses/gpl-3.0.txt)
2
+ # Copyright (C) 2013-2016 all contributors <yahns-public@yhbt.net>
3
+ # License: GPL-3.0+ (https://www.gnu.org/licenses/gpl-3.0.txt)
4
+ # frozen_string_literal: true
4
5
  #
5
6
  # This is the dangerous, low-level epoll interface for sleepy_penguin
6
7
  # It is safe as long as you're aware of all potential concurrency
@@ -32,7 +33,7 @@ def queue_mod(io, flags)
32
33
  end
33
34
 
34
35
  def thr_init
35
- Thread.current[:yahns_rbuf] = ""
36
+ Thread.current[:yahns_rbuf] = ''.dup
36
37
  Thread.current[:yahns_fdmap] = @fdmap
37
38
  Thread.current[:yahns_queue] = self
38
39
  end
@@ -1,6 +1,7 @@
1
1
  # -*- encoding: binary -*-
2
- # Copyright (C) 2013-2015 all contributors <yahns-public@yhbt.net>
3
- # License: GPLv3 or later (https://www.gnu.org/licenses/gpl-3.0.txt)
2
+ # Copyright (C) 2013-2016 all contributors <yahns-public@yhbt.net>
3
+ # License: GPL-3.0+ (https://www.gnu.org/licenses/gpl-3.0.txt)
4
+ # frozen_string_literal: true
4
5
  #
5
6
  # This is the dangerous, low-level kqueue interface for sleepy_penguin
6
7
  # It is safe as long as you're aware of all potential concurrency
@@ -41,7 +42,7 @@ def queue_mod(io, flags)
41
42
  end
42
43
 
43
44
  def thr_init
44
- Thread.current[:yahns_rbuf] = ""
45
+ Thread.current[:yahns_rbuf] = ''.dup
45
46
  Thread.current[:yahns_fdmap] = @fdmap
46
47
  Thread.current[:yahns_queue] = self
47
48
  end
@@ -1,5 +1,6 @@
1
- # Copyright (C) 2013-2015 all contributors <yahns-public@yhbt.net>
2
- # License: GPLv3 or later (https://www.gnu.org/licenses/gpl-3.0.txt)
1
+ # Copyright (C) 2013-2016 all contributors <yahns-public@yhbt.net>
2
+ # License: GPL-3.0+ (https://www.gnu.org/licenses/gpl-3.0.txt)
3
+ # frozen_string_literal: true
3
4
 
4
5
  require 'sleepy_penguin'
5
6
 
@@ -1,5 +1,6 @@
1
- # Copyright (C) 2013-2015 all contributors <yahns-public@yhbt.net>
2
- # License: GPLv3 or later (https://www.gnu.org/licenses/gpl-3.0.txt)
1
+ # Copyright (C) 2013-2016 all contributors <yahns-public@yhbt.net>
2
+ # License: GPL-3.0+ (https://www.gnu.org/licenses/gpl-3.0.txt)
3
+ # frozen_string_literal: true
3
4
  #
4
5
  # POSIX pipe version, see queue_quitter.rb for the (preferred) eventfd one
5
6
  class Yahns::QueueQuitter # :nodoc:
@@ -1,6 +1,7 @@
1
1
  # -*- encoding: binary -*-
2
- # Copyright (C) 2013-2015 all contributors <yahns-public@yhbt.net>
3
- # License: GPLv3 or later (https://www.gnu.org/licenses/gpl-3.0.txt)
2
+ # Copyright (C) 2013-2016 all contributors <yahns-public@yhbt.net>
3
+ # License: GPL-3.0+ (https://www.gnu.org/licenses/gpl-3.0.txt)
4
+ # frozen_string_literal: true
4
5
  require 'rack'
5
6
  class Yahns::Rack # :nodoc:
6
7
  attr_reader :preload
@@ -62,10 +63,10 @@ def app_defaults
62
63
  "rack.run_once" => false,
63
64
  "rack.hijack?" => true,
64
65
  "rack.version" => [ 1, 2 ],
65
- "SCRIPT_NAME" => "",
66
+ "SCRIPT_NAME" => ''.dup,
66
67
 
67
68
  # this is not in the Rack spec, but some apps may rely on it
68
- "SERVER_SOFTWARE" => "yahns"
69
+ "SERVER_SOFTWARE" => 'yahns'.dup
69
70
  }
70
71
  end
71
72
 
@@ -1,5 +1,6 @@
1
- # Copyright (C) 2013-2014, all contributors
2
- # License: GPLv3 or later (https://www.gnu.org/licenses/gpl-3.0.txt)
1
+ # Copyright (C) 2013-2016 all contributors <yahns-public@yhbt.net>
2
+ # License: GPL-3.0+ (https://www.gnu.org/licenses/gpl-3.0.txt)
3
+ # frozen_string_literal: true
3
4
  require_relative '../yahns'
4
5
 
5
6
  module Yahns::RackupHandler # :nodoc:
@@ -38,6 +39,7 @@ def self.run(app, o)
38
39
  Yahns::Server.new(cfg).start.join
39
40
  end
40
41
 
42
+ # this is called by Rack::Server
41
43
  def self.valid_options
42
44
  # these should be the most common options
43
45
  {
@@ -1,12 +1,13 @@
1
1
  # -*- encoding: binary -*-
2
- # Copyright (C) 2013-2015 all contributors <yahns-public@yhbt.net>
3
- # License: GPLv3 or later (https://www.gnu.org/licenses/gpl-3.0.txt)
2
+ # Copyright (C) 2013-2016 all contributors <yahns-public@yhbt.net>
3
+ # License: GPL-3.0+ (https://www.gnu.org/licenses/gpl-3.0.txt)
4
+ # frozen_string_literal: true
4
5
 
5
- module Yahns::SendfileCompat
6
+ module Yahns::SendfileCompat # :nodoc:
6
7
  def trysendfile(io, offset, count)
7
8
  return 0 if count == 0
8
9
  count = 0x4000 if count > 0x4000
9
- buf = Thread.current[:yahns_sfbuf] ||= ''
10
+ buf = Thread.current[:yahns_sfbuf] ||= ''.dup
10
11
  io.pos = offset
11
12
  str = io.read(count, buf) or return # nil for EOF
12
13
  n = 0
@@ -21,7 +22,3 @@ def trysendfile(io, offset, count)
21
22
  end while true
22
23
  end
23
24
  end
24
-
25
- class IO
26
- include Yahns::SendfileCompat
27
- end
@@ -1,5 +1,6 @@
1
- # Copyright (C) 2013-2015 all contributors <yahns-public@yhbt.net>
2
- # License: GPLv3 or later (https://www.gnu.org/licenses/gpl-3.0.txt)
1
+ # Copyright (C) 2013-2016 all contributors <yahns-public@yhbt.net>
2
+ # License: GPL-3.0+ (https://www.gnu.org/licenses/gpl-3.0.txt)
3
+ # frozen_string_literal: true
3
4
  require_relative 'queue_quitter'
4
5
  require_relative 'tcp_server'
5
6
  require_relative 'unix_server'
@@ -379,7 +380,17 @@ def fdmap_init
379
380
  ctx.queue = queues[qegg] ||= qegg_vivify(qegg, fdmap)
380
381
  ctx = ctx.dup
381
382
  ctx.__send__(:include, l.expire_mod)
382
- ctx.__send__(:include, Yahns::OpenSSLClient) if opts[:ssl_ctx]
383
+ if ssl_ctx = opts[:ssl_ctx]
384
+ ctx.__send__(:include, Yahns::OpenSSLClient)
385
+ env = ctx.app_defaults = ctx.app_defaults.dup
386
+ env['HTTPS'] = 'on' # undocumented, but Rack::Request uses this
387
+ env['rack.url_scheme'] = 'https'
388
+
389
+ # call OpenSSL::SSL::SSLContext#setup explicitly here to detect
390
+ # errors and avoid race conditions. We avoid calling this in the
391
+ # parent process since
392
+ ssl_ctx.setup
393
+ end
383
394
  ctx_list << ctx
384
395
  # acceptors feed the the queues
385
396
  l.spawn_acceptor(opts[:threads] || 1, @logger, ctx)