rackup 2.2.0 → 2.3.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 500a1eebb3f2dc73a7f4e0b50753603f19f4b2c841a55c01c047188ed6d2214f
4
- data.tar.gz: 7e51b56d52e396e9c208b06c7a25be3389d0df9c55c3c3333f0379e5aec73719
3
+ metadata.gz: 18162c3f490c041f7b861caf10d48fcd77e81a5e209dbabb1b3f7ec09ccd5145
4
+ data.tar.gz: 92e5b171f36c54799a05ef413acef33128805fac66c082272a1548aca2234f02
5
5
  SHA512:
6
- metadata.gz: 9aa96ee4990bf4d93f23c4d3d2b16b28c793e9f4fabc2a24a007f241067262168608bcf0e2091368131563dfe9bb4b7fc2845330a75e96c7886b956a12e5f933
7
- data.tar.gz: 62821749a10a8f337c3f0b4dde6f83fab067c68a1d3864f74a8cd1b28fb62d8be8430a571112ea5f5b60b753ad278140d130ec3f73c3a67f739345b288f73a49
6
+ metadata.gz: 8bbd6a449a64bf48fba176d81c61f13e8eab2888853576effaa8ebf85e9579798ad2069655d9ac123322aafed5a2656bd0bd83f39e53558119e3827310fce3f6
7
+ data.tar.gz: d56e025ca3edfa363e94a566e356629b306c46c3490d91e7cf70a6d77d37fc4c20da30337a6c66103eccf32e71a6182c989850d965dce163b3a3566ff1faa83c
@@ -16,6 +16,19 @@ require_relative '../stream'
16
16
  module Rackup
17
17
  module Handler
18
18
  class WEBrick < ::WEBrick::HTTPServlet::AbstractServlet
19
+ # A WEBrick HTTPServer subclass that invokes the Rack app directly,
20
+ # bypassing the mount table and default OPTIONS * handling.
21
+ class Server < ::WEBrick::HTTPServer
22
+ def initialize(app, config)
23
+ super(config)
24
+ @handler = Handler::WEBrick.new(self, app)
25
+ end
26
+
27
+ def service(req, res)
28
+ @handler.service(req, res)
29
+ end
30
+ end
31
+
19
32
  def self.run(app, **options)
20
33
  environment = ENV['RACK_ENV'] || 'development'
21
34
  default_host = environment == 'development' ? 'localhost' : nil
@@ -28,8 +41,7 @@ module Rackup
28
41
  require 'webrick/https'
29
42
  end
30
43
 
31
- @server = ::WEBrick::HTTPServer.new(options)
32
- @server.mount "/", Rackup::Handler::WEBrick, app
44
+ @server = Server.new(app, options)
33
45
  yield @server if block_given?
34
46
  @server.start
35
47
  end
@@ -102,11 +114,25 @@ module Rackup
102
114
  )
103
115
 
104
116
  env[::Rack::QUERY_STRING] ||= ""
105
- unless env[::Rack::PATH_INFO] == ""
106
- path, n = req.request_uri.path, env[::Rack::SCRIPT_NAME].length
107
- env[::Rack::PATH_INFO] = path[n, path.length - n]
117
+
118
+ # Handle OPTIONS * requests which have no path
119
+ if req.unparsed_uri == "*"
120
+ env[::Rack::PATH_INFO] = "*"
121
+ env[::Rack::REQUEST_PATH] = "*"
122
+
123
+ # Ensure SERVER_NAME and SERVER_PORT are set from server config
124
+ # (WEBrick allows these to be nil for OPTIONS * requests)
125
+ # See https://github.com/ruby/webrick/pull/182 for a proper fix.
126
+ env[::Rack::SERVER_NAME] ||= @server[:ServerName] || @server[:BindAddress] || "localhost"
127
+ env[::Rack::SERVER_PORT] ||= (@server[:Port] || 80).to_s
128
+ else
129
+ unless env[::Rack::PATH_INFO] == ""
130
+ # Strip the script name prefix from the path to get path info
131
+ script_name_length = env[::Rack::SCRIPT_NAME].length
132
+ env[::Rack::PATH_INFO] = req.request_uri.path[script_name_length..-1] || ""
133
+ end
134
+ env[::Rack::REQUEST_PATH] ||= env[::Rack::SCRIPT_NAME] + env[::Rack::PATH_INFO]
108
135
  end
109
- env[::Rack::REQUEST_PATH] ||= [env[::Rack::SCRIPT_NAME], env[::Rack::PATH_INFO]].join
110
136
 
111
137
  status, headers, body = @app.call(env)
112
138
  begin
data/lib/rackup/server.rb CHANGED
@@ -170,14 +170,14 @@ module Rackup
170
170
  # This method can be used to very easily launch a CGI application, for
171
171
  # example:
172
172
  #
173
- # Rack::Server.start(
173
+ # Rackup::Server.start(
174
174
  # :app => lambda do |e|
175
175
  # [200, {'content-type' => 'text/html'}, ['hello world']]
176
176
  # end,
177
177
  # :server => 'cgi'
178
178
  # )
179
179
  #
180
- # Further options available here are documented on Rack::Server#initialize
180
+ # Further options available here are documented on Rackup::Server#initialize
181
181
  def self.start(options = nil)
182
182
  new(options).start
183
183
  end
@@ -4,5 +4,5 @@
4
4
  # Copyright, 2022-2023, by Samuel Williams.
5
5
 
6
6
  module Rackup
7
- VERSION = "2.2.0"
7
+ VERSION = "2.3.0"
8
8
  end
data/lib/rackup.rb CHANGED
@@ -6,3 +6,16 @@
6
6
  require_relative 'rackup/handler'
7
7
  require_relative 'rackup/server'
8
8
  require_relative 'rackup/version'
9
+
10
+ begin
11
+ # Although webrick is gone from Ruby since 3.0, it still warns all the way
12
+ # through to 3.3. Only on 3.4 will requiring it not produce a warning anymore.
13
+ verbose, $VERBOSE = $VERBOSE, nil
14
+ require 'webrick'
15
+ # If the user happens to have webrick in their bundle, make the handler available.
16
+ require_relative 'rackup/handler/webrick'
17
+ rescue LoadError
18
+ # ¯\_(ツ)_/¯
19
+ ensure
20
+ $VERBOSE = verbose
21
+ end
data/readme.md CHANGED
@@ -24,6 +24,24 @@ $ rackup
24
24
 
25
25
  Your application should now be available locally, typically `http://localhost:9292`.
26
26
 
27
+ ### Server Handler
28
+
29
+ You can also use `Rackup::Handler` to start a server programmatically:
30
+
31
+ ``` ruby
32
+ require 'rackup'
33
+
34
+ # Use the default server:
35
+ handler = Rackup::Handler.default
36
+ handler.run(app, **options)
37
+
38
+ # Use a specific server:
39
+ handler = Rackup::Handler.get('puma')
40
+ handler.run(app, **options)
41
+ ```
42
+
43
+ Do not require specific handlers or assume they will exist/work. Instead, use the `default` method to get the best available handler.
44
+
27
45
  ## (Soft) Deprecation
28
46
 
29
47
  For a long time, `rackup` (the executable and implementation) was part of `rack`, and `webrick` was the default server, included with Ruby. It made it easy to run a Rack application without having to worry about the details of the server - great for documentation and demos.
data/releases.md CHANGED
@@ -2,6 +2,27 @@
2
2
 
3
3
  All notable changes to this project will be documented in this file. For info on how to format all future additions to this file please reference [Keep A Changelog](https://keepachangelog.com/en/1.0.0/).
4
4
 
5
+ ## v2.2.1
6
+
7
+ - Try to require `webrick` and `rackup/handler/webrick` by default, for compatibility with code that expects them to be available.
8
+
5
9
  ## v2.2.0
6
10
 
7
11
  - Remove old rack shims.
12
+ - Remove `webrick` dependency.
13
+
14
+ ## v2.1.0
15
+
16
+ - Correctly support streaming responses with `webrick`.
17
+
18
+ ## v2.0.0
19
+
20
+ - Initial release and migration of code from `rack`.
21
+
22
+ ## v1.0.1
23
+
24
+ - Fix `rackup.rb` invalid requires.
25
+
26
+ ## v1.0.0
27
+
28
+ - Initial release of empty shim for Rack v2.
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rackup
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.2.0
4
+ version: 2.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Samuel Williams
@@ -64,10 +64,9 @@ authors:
64
64
  - Wyatt Pan
65
65
  - Yehuda Katz
66
66
  - Zachary Scott
67
- autorequire:
68
67
  bindir: bin
69
68
  cert_chain: []
70
- date: 2024-11-02 00:00:00.000000000 Z
69
+ date: 1980-01-02 00:00:00.000000000 Z
71
70
  dependencies:
72
71
  - !ruby/object:Gem::Dependency
73
72
  name: rack
@@ -83,8 +82,6 @@ dependencies:
83
82
  - - ">="
84
83
  - !ruby/object:Gem::Version
85
84
  version: '3'
86
- description:
87
- email:
88
85
  executables:
89
86
  - rackup
90
87
  extensions: []
@@ -107,9 +104,9 @@ homepage: https://github.com/rack/rackup
107
104
  licenses:
108
105
  - MIT
109
106
  metadata:
107
+ changelog_uri: https://github.com/rack/rackup/blob/main/releases.md
110
108
  rubygems_mfa_required: 'true'
111
109
  source_code_uri: https://github.com/rack/rackup.git
112
- post_install_message:
113
110
  rdoc_options: []
114
111
  require_paths:
115
112
  - lib
@@ -124,8 +121,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
124
121
  - !ruby/object:Gem::Version
125
122
  version: '0'
126
123
  requirements: []
127
- rubygems_version: 3.5.11
128
- signing_key:
124
+ rubygems_version: 3.6.9
129
125
  specification_version: 4
130
126
  summary: A general server command for Rack applications.
131
127
  test_files: []