Sha256: 2adf3ebef623460250564326ad868613fdc71b597d5d558e77cb9c6b3b41c445
Contents?: true
Size: 911 Bytes
Versions: 16
Compression:
Stored size: 911 Bytes
Contents
module Olelo module Middleware class ForceEncoding def initialize(app, encoding = Encoding.default_external) @app, @encoding = app, encoding end def call(env) request = Rack::Request.new(env) encode(env) encode(request.params) @app.call(env) end private def encode(x) case x when Hash y = x.frozen? ? {} : x x.each { |k,v| y[k] = encode(v) } y when Array y = x.frozen? ? [] : x x.each_with_index {|v,i| y[i] = encode(v) } y when String # Try to force encoding and revert to old encoding if this doesn't work if x.encoding != @encoding x = x.dup if x.frozen? x.try_encoding(@encoding) else x end else x end end end end end
Version data entries
16 entries across 16 versions & 1 rubygems