Skip to content

Commit

Permalink
Merge pull request #977 from metikular/feature/support-symbol-headers
Browse files Browse the repository at this point in the history
Fix webhook requests for headers with a symbol key
  • Loading branch information
paulomarg authored Jun 29, 2022
2 parents eccef0c + 12abba9 commit a176969
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ Note: For changes to the API, see https://shopify.dev/changelog?filter=api
## Unreleased

- [#979](https://github.com/Shopify/shopify_api/pull/979) Update `ShopifyAPI::Context.setup` to take `old_api_secret_key` to support API credentials rotation
- [#977](https://github.com/Shopify/shopify_api/pull/977) Fix webhook requests when a header is present having a symbol key (e.g. `:clearance`)

## Version 10.1.0

Expand Down
2 changes: 1 addition & 1 deletion lib/shopify_api/webhooks/request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def parsed_body
sig { params(raw_body: String, headers: T::Hash[String, T.untyped]).void }
def initialize(raw_body:, headers:)
# normalize the headers by forcing lowercase, removing any prepended "http"s, and changing underscores to dashes
headers = headers.to_h { |k, v| [k.downcase.sub("http_", "").gsub("_", "-"), v] }
headers = headers.to_h { |k, v| [k.to_s.downcase.sub("http_", "").gsub("_", "-"), v] }

missing_headers = []
[
Expand Down
11 changes: 11 additions & 0 deletions test/webhooks/request_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,17 @@ def test_error_when_headers_missing
ShopifyAPI::Webhooks::Request.new(raw_body: "{}", headers: {})
end
end

def test_with_symbol_headers
headers = {
"HTTP_X_SHOPIFY_TOPIC" => "some/topic",
"HTTP_X_SHOPIFY_HMAC_SHA256" => "some_hmac",
"HTTP_X_SHOPIFY_SHOP_DOMAIN" => "shop.myshopify.com",
:clearance => "session",
}

assert(ShopifyAPI::Webhooks::Request.new(raw_body: "{}", headers: headers))
end
end
end
end

0 comments on commit a176969

Please sign in to comment.