Skip to content

fix: move require into TwilioWebhookAuthentication initialize (Fixes twilio/twilio-ruby#592) #597

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions lib/rack/twilio_webhook_authentication.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# frozen_string_literal: true

require 'rack/media_type'

module Rack
# Middleware that authenticates webhooks from Twilio using the request
# validator.
Expand All @@ -23,9 +21,9 @@ module Rack
class TwilioWebhookAuthentication
# Rack's FORM_DATA_MEDIA_TYPES can be modified to taste, so we're slightly
# more conservative in what we consider form data.
FORM_URLENCODED_MEDIA_TYPE = Rack::MediaType.type('application/x-www-form-urlencoded')

def initialize(app, auth_token, *paths, &auth_token_lookup)
require 'rack/media_type'

@app = app
@auth_token = auth_token
define_singleton_method(:get_auth_token, auth_token_lookup) if block_given?
Expand Down Expand Up @@ -57,7 +55,7 @@ def call(env)
def extract_params!(request)
return {} unless request.post?

if request.media_type == FORM_URLENCODED_MEDIA_TYPE
if request.media_type == Rack::MediaType.type('application/x-www-form-urlencoded')
request.POST
else
request.body.rewind
Expand Down