mirror of
https://github.com/ditkrg/idempotent-request.git
synced 2026-01-23 14:27:22 +00:00
- fix an issue when getting an exception inside application would not delete lock, so client could receive 429 after 500
33 lines
636 B
Ruby
33 lines
636 B
Ruby
module IdempotentRequest
|
|
class Request
|
|
attr_reader :request
|
|
|
|
def initialize(env, config = {})
|
|
@request = Rack::Request.new(env)
|
|
@header_name = config.fetch(:header_key, 'HTTP_IDEMPOTENCY_KEY')
|
|
end
|
|
|
|
def key
|
|
request.env[header_name]
|
|
end
|
|
|
|
def method_missing(method, *args)
|
|
if request.respond_to?(method)
|
|
request.send(method, *args)
|
|
else
|
|
super
|
|
end
|
|
end
|
|
|
|
private
|
|
|
|
def header_name
|
|
key = @header_name.to_s
|
|
.upcase
|
|
.tr('-', '_')
|
|
|
|
key.start_with?('HTTP_') ? key : "HTTP_#{key}"
|
|
end
|
|
end
|
|
end
|