unicorn 5.5.5 → 5.6.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f965b97839a0a17b9df6cf014ca2780d0523a794c5c63be4f9d05973de588826
4
- data.tar.gz: 36152775b38d84fb2fd3e720ff248012914b59ec4bbcbb0589122dde2ea34a50
3
+ metadata.gz: 69fbb02b06dc0994ca06e592be20a2bc877bb923d0f621e940f00df61d801799
4
+ data.tar.gz: 9a4b8ace3ae35f175285be916a3ed8e8da2f341e3e713c475c8e1e3a5481c8b9
5
5
  SHA512:
6
- metadata.gz: 1d9115ad5b084f5fdf710038412988892691248c0e5e05bde3230c6381adef090f53c30e4b3ad00d0de6f3467007c1acc962cd9cb836f28727690a2bf12d8466
7
- data.tar.gz: 2db26ec37e81e4c1d4a549751c74a280f4304df9dfd9e13d1be40792648808d6b45b48f57c9d4460dbe7ba2b45b9a05c51c30ea73a54b9b1f004089c9992bb34
6
+ metadata.gz: 923c5153a1a21924bd41da7ff8c9a49313226627b72f9041f1e4fbf74ce1d5439d6a504df3632174e04b764ac43c4c77d86ee0afa740041ba1bb1f0939c27af2
7
+ data.tar.gz: a7ade3d40a68d9f663fa3b8a402bda78e189086767b29463e634d64f946877bd28f693545979d60bbc13cbfb71700bc315da364d1774156f8050c880c0ca6537
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
- DEF_VER = "v5.5.5"
2
+ DEF_VER = "v5.6.0"
3
3
  CONSTANT = "Unicorn::Const::UNICORN_VERSION"
4
4
  RVF = "lib/unicorn/version.rb"
5
5
  GVF = "GIT-VERSION-FILE"
@@ -53,6 +53,7 @@ class Unicorn::Configurator
53
53
  server.logger.info("worker=#{worker.nr} ready")
54
54
  },
55
55
  :pid => nil,
56
+ :early_hints => false,
56
57
  :worker_exec => false,
57
58
  :preload_app => false,
58
59
  :check_client_connection => false,
@@ -276,6 +277,15 @@ def default_middleware(bool)
276
277
  set_bool(:default_middleware, bool)
277
278
  end
278
279
 
280
+ # sets whether to enable the proposed early hints Rack API.
281
+ # If enabled, Rails 5.2+ will automatically send a 103 Early Hint
282
+ # for all the `javascript_include_tag` and `stylesheet_link_tag`
283
+ # in your response. See: https://api.rubyonrails.org/v5.2/classes/ActionDispatch/Request.html#method-i-send_early_hints
284
+ # See also https://tools.ietf.org/html/rfc8297
285
+ def early_hints(bool)
286
+ set_bool(:early_hints, bool)
287
+ end
288
+
279
289
  # sets listeners to the given +addresses+, replacing or augmenting the
280
290
  # current set. This is for the global listener pool shared by all
281
291
  # worker processes. For per-worker listeners, see the after_fork example
@@ -15,7 +15,7 @@ class Unicorn::HttpServer
15
15
  :before_fork, :after_fork, :before_exec,
16
16
  :listener_opts, :preload_app,
17
17
  :orig_app, :config, :ready_pipe, :user,
18
- :default_middleware
18
+ :default_middleware, :early_hints
19
19
  attr_writer :after_worker_exit, :after_worker_ready, :worker_exec
20
20
 
21
21
  attr_reader :pid, :logger
@@ -588,6 +588,25 @@ def handle_error(client, e)
588
588
  rescue
589
589
  end
590
590
 
591
+ def e103_response_write(client, headers)
592
+ response = if @request.response_start_sent
593
+ "103 Early Hints\r\n"
594
+ else
595
+ "HTTP/1.1 103 Early Hints\r\n"
596
+ end
597
+
598
+ headers.each_pair do |k, vs|
599
+ next if !vs || vs.empty?
600
+ values = vs.to_s.split("\n".freeze)
601
+ values.each do |v|
602
+ response << "#{k}: #{v}\r\n"
603
+ end
604
+ end
605
+ response << "\r\n".freeze
606
+ response << "HTTP/1.1 ".freeze if @request.response_start_sent
607
+ client.write(response)
608
+ end
609
+
591
610
  def e100_response_write(client, env)
592
611
  # We use String#freeze to avoid allocations under Ruby 2.1+
593
612
  # Not many users hit this code path, so it's better to reduce the
@@ -602,7 +621,15 @@ def e100_response_write(client, env)
602
621
  # once a client is accepted, it is processed in its entirety here
603
622
  # in 3 easy steps: read request, call app, write app response
604
623
  def process_client(client)
605
- status, headers, body = @app.call(env = @request.read(client))
624
+ env = @request.read(client)
625
+
626
+ if early_hints
627
+ env["rack.early_hints"] = lambda do |headers|
628
+ e103_response_write(client, headers)
629
+ end
630
+ end
631
+
632
+ status, headers, body = @app.call(env)
606
633
 
607
634
  begin
608
635
  return if @request.hijacked?
@@ -23,6 +23,16 @@ def call(env)
23
23
  end
24
24
  end
25
25
 
26
+ class TestEarlyHintsHandler
27
+ def call(env)
28
+ while env['rack.input'].read(4096)
29
+ end
30
+ env['rack.early_hints'].call(
31
+ "Link" => "</style.css>; rel=preload; as=style\n</script.js>; rel=preload"
32
+ )
33
+ [200, { 'Content-Type' => 'text/plain' }, ['hello!\n']]
34
+ end
35
+ end
26
36
 
27
37
  class WebServerTest < Test::Unit::TestCase
28
38
 
@@ -84,6 +94,26 @@ def test_preload_app_config
84
94
  tmp.close!
85
95
  end
86
96
 
97
+ def test_early_hints
98
+ teardown
99
+ redirect_test_io do
100
+ @server = HttpServer.new(TestEarlyHintsHandler.new,
101
+ :listeners => [ "127.0.0.1:#@port"],
102
+ :early_hints => true)
103
+ @server.start
104
+ end
105
+
106
+ sock = TCPSocket.new('127.0.0.1', @port)
107
+ sock.syswrite("GET / HTTP/1.0\r\n\r\n")
108
+
109
+ responses = sock.read(4096)
110
+ assert_match %r{\AHTTP/1.[01] 103\b}, responses
111
+ assert_match %r{^Link: </style\.css>}, responses
112
+ assert_match %r{^Link: </script\.js>}, responses
113
+
114
+ assert_match %r{^HTTP/1.[01] 200\b}, responses
115
+ end
116
+
87
117
  def test_broken_app
88
118
  teardown
89
119
  app = lambda { |env| raise RuntimeError, "hello" }
@@ -11,7 +11,7 @@
11
11
 
12
12
  Gem::Specification.new do |s|
13
13
  s.name = %q{unicorn}
14
- s.version = (ENV['VERSION'] || '5.5.5').dup
14
+ s.version = (ENV['VERSION'] || '5.6.0').dup
15
15
  s.authors = ['unicorn hackers']
16
16
  s.summary = 'Rack HTTP server for fast clients and Unix'
17
17
  s.description = File.read('README').split("\n\n")[1]
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: unicorn
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.5.5
4
+ version: 5.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - unicorn hackers
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-04-27 00:00:00.000000000 Z
11
+ date: 2020-07-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rack