Class: Sinatra::Base
- Inherits:
-
Object
- Object
- Sinatra::Base
- Defined in:
- lib/sinatra_opal_patches.rb
Overview
-
Base#static! (upstream base.rb:1147)
Upstream: URI_INSTANCE.unescape — URI_INSTANCE is defined in upstream as URI::RFC2396_PARSER (populated in opal_patches.rb with a CGI-backed stand-in), so this works today. The homura port also dropped the ‘static_headers` setting (not used on Workers — static files are served from R2 or a CDN, not from per-request Ruby response headers). Keeping parity here.
Class Method Summary collapse
-
.force_encoding(data, encoding = default_encoding) ⇒ Object
———————————————————– 12.
- .new!(*args, &block) ⇒ Object
-
.setup_default_middleware(builder) ⇒ Object
———————————————————– 10.
Class Method Details
.force_encoding(data, encoding = default_encoding) ⇒ Object
-
Base.force_encoding (upstream base.rb:1942)
Upstream calls ‘.force_encoding(encoding).encode!`. Opal’s String#encode! raises NotImplementedError (JS Strings are immutable UTF-16). force_encoding alone is a no-op that returns the same String object. Drop encode!.
280 281 282 283 284 285 286 287 288 289 290 291 292 |
# File 'lib/sinatra_opal_patches.rb', line 280 def force_encoding(data, encoding = default_encoding) return if data == settings || data.is_a?(Tempfile) if data.respond_to?(:force_encoding) data.force_encoding(encoding) elsif data.respond_to?(:each_value) data.each_value { |v| force_encoding(v, encoding) } elsif data.respond_to?(:each) data.each { |v| force_encoding(v, encoding) } end data end |
.new!(*args, &block) ⇒ Object
230 231 232 233 234 |
# File 'lib/sinatra_opal_patches.rb', line 230 def new!(*args, &block) instance = allocate instance.send(:initialize, *args, &block) instance end |
.setup_default_middleware(builder) ⇒ Object
-
Base.setup_default_middleware (upstream base.rb:1846)
Upstream invokes ‘setup_host_authorization` which uses IPAddr. homura does not use host_authorization on Workers (the request host is always whitelisted by the Worker binding itself; permitted_hosts is moot). Skip that middleware.
244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 |
# File 'lib/sinatra_opal_patches.rb', line 244 def setup_default_middleware(builder) builder.use ExtendedRack builder.use ShowExceptions if show_exceptions? builder.use ::Rack::MethodOverride if method_override? builder.use ::Rack::Head setup_logging(builder) setup_sessions(builder) setup_protection(builder) # NOTE: upstream calls `setup_host_authorization builder` here. # On Cloudflare Workers the host whitelist is enforced by the # wrangler.toml binding configuration itself, and the # `Rack::Protection::HostAuthorization` middleware is not vendored # (would require IPAddr, also stubbed in homura). Skipping it # is functionally equivalent in our deployment model. end |