hooks-ruby 0.0.4 → 0.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2cab1bf1a1f61011d053be5beb9d48738bd439303b87743e41e10df0b4b9d65c
4
- data.tar.gz: 9b9abc62fff8f0f2f77ad94949bc7e067fff5a2f072bbf73f8e6e55c03865714
3
+ metadata.gz: 9025d70b78a67040f436318091d556090c7f17e9dffe094b6437bde394ef7010
4
+ data.tar.gz: 24cf76930b63917dad1795a72113b9cf0646330671983b60bd367cc04d11d015
5
5
  SHA512:
6
- metadata.gz: 40f769a697bd61c6c851eef217fadc66387c49d37c19639a283dd770ca8be8889a13eeba2785a41c53edcdef29327231527405a9de21b2b4620416196da792c2
7
- data.tar.gz: 119a371d927f240aefe4e74c822b48318032250e7cbf060a9bd077b1375823137b419f7d1e2d27d775e6468d38843afb45ec9c8cd8a71a22d82226160c66043e
6
+ metadata.gz: 0e8acdf59a00128c3a68fb2db10864c0e0bf6a5e454aabceaf824cdf4ba62f8057f166da2dae0f17238a7a280137861ca4ba1da70b33165e6e890becb36be391
7
+ data.tar.gz: 33178114bcbbda82ecf91cd27bfd7633621f6d7f2ea64fc3891596a8769cc80dac55ceab5c4fc75cd035d2a0188c9da2821743442cfcdbbce0cef2d3d479e6b5
data/lib/hooks/app/api.rb CHANGED
@@ -102,13 +102,13 @@ module Hooks
102
102
  validate_auth!(raw_body, headers, endpoint_config, config)
103
103
  end
104
104
 
105
- payload = parse_payload(raw_body, headers, symbolize: config[:symbolize_payload])
105
+ payload = parse_payload(raw_body, headers, symbolize: false)
106
106
  handler = load_handler(handler_class_name)
107
- normalized_headers = config[:normalize_headers] ? Hooks::Utils::Normalize.headers(headers) : headers
107
+ processed_headers = config[:normalize_headers] ? Hooks::Utils::Normalize.headers(headers) : headers
108
108
 
109
109
  response = handler.call(
110
110
  payload:,
111
- headers: normalized_headers,
111
+ headers: processed_headers,
112
112
  config: endpoint_config
113
113
  )
114
114
 
@@ -44,9 +44,9 @@ module Hooks
44
44
  #
45
45
  # @param raw_body [String] The raw request body
46
46
  # @param headers [Hash] The request headers
47
- # @param symbolize [Boolean] Whether to symbolize keys in parsed JSON (default: true)
48
- # @return [Hash, String] Parsed JSON as Hash (optionally symbolized), or raw body if not JSON
49
- def parse_payload(raw_body, headers, symbolize: true)
47
+ # @param symbolize [Boolean] Whether to symbolize keys in parsed JSON (default: false)
48
+ # @return [Hash, String] Parsed JSON as Hash with string keys, or raw body if not JSON
49
+ def parse_payload(raw_body, headers, symbolize: false)
50
50
  # Optimized content type check - check most common header first
51
51
  content_type = headers["Content-Type"] || headers["CONTENT_TYPE"] || headers["content-type"] || headers["HTTP_CONTENT_TYPE"]
52
52
 
@@ -55,6 +55,7 @@ module Hooks
55
55
  begin
56
56
  # Security: Limit JSON parsing depth and complexity to prevent JSON bombs
57
57
  parsed_payload = safe_json_parse(raw_body)
58
+ # Note: symbolize parameter is kept for backward compatibility but defaults to false
58
59
  parsed_payload = parsed_payload.transform_keys(&:to_sym) if symbolize && parsed_payload.is_a?(Hash)
59
60
  return parsed_payload
60
61
  rescue JSON::ParserError, ArgumentError => e
@@ -20,7 +20,6 @@ module Hooks
20
20
  production: true,
21
21
  endpoints_dir: "./config/endpoints",
22
22
  use_catchall_route: false,
23
- symbolize_payload: true,
24
23
  normalize_headers: true
25
24
  }.freeze
26
25
 
@@ -141,7 +140,6 @@ module Hooks
141
140
  "HOOKS_ENVIRONMENT" => :environment,
142
141
  "HOOKS_ENDPOINTS_DIR" => :endpoints_dir,
143
142
  "HOOKS_USE_CATCHALL_ROUTE" => :use_catchall_route,
144
- "HOOKS_SYMBOLIZE_PAYLOAD" => :symbolize_payload,
145
143
  "HOOKS_NORMALIZE_HEADERS" => :normalize_headers,
146
144
  "HOOKS_SOME_STRING_VAR" => :some_string_var # Added for test
147
145
  }
@@ -154,7 +152,7 @@ module Hooks
154
152
  case config_key
155
153
  when :request_limit, :request_timeout
156
154
  env_config[config_key] = value.to_i
157
- when :use_catchall_route, :symbolize_payload, :normalize_headers
155
+ when :use_catchall_route, :normalize_headers
158
156
  # Convert string to boolean
159
157
  env_config[config_key] = %w[true 1 yes on].include?(value.downcase)
160
158
  else
@@ -26,7 +26,6 @@ module Hooks
26
26
  optional(:environment).filled(:string, included_in?: %w[development production])
27
27
  optional(:endpoints_dir).filled(:string)
28
28
  optional(:use_catchall_route).filled(:bool)
29
- optional(:symbolize_payload).filled(:bool)
30
29
  optional(:normalize_headers).filled(:bool)
31
30
  end
32
31
 
@@ -15,8 +15,8 @@ module Hooks
15
15
  # Process a webhook request
16
16
  #
17
17
  # @param payload [Hash, String] Parsed request body (JSON Hash) or raw string
18
- # @param headers [Hash<String, String>] HTTP headers
19
- # @param config [Hash] Merged endpoint configuration including opts section
18
+ # @param headers [Hash] HTTP headers (string keys, optionally normalized - default is normalized)
19
+ # @param config [Hash] Merged endpoint configuration including opts section (symbolized keys)
20
20
  # @return [Hash, String, nil] Response body (will be auto-converted to JSON)
21
21
  # @raise [NotImplementedError] if not implemented by subclass
22
22
  def call(payload:, headers:, config:)
@@ -58,6 +58,39 @@ module Hooks
58
58
  normalized
59
59
  end
60
60
 
61
+ # Symbolize header keys in a hash
62
+ #
63
+ # @param headers [Hash, #each] Headers hash or hash-like object
64
+ # @return [Hash] Hash with symbolized keys (hyphens converted to underscores)
65
+ #
66
+ # @example Header symbolization
67
+ # headers = { "content-type" => "application/json", "x-github-event" => "push" }
68
+ # symbolized = Normalize.symbolize_headers(headers)
69
+ # # => { content_type: "application/json", x_github_event: "push" }
70
+ #
71
+ # @example Handle various input types
72
+ # Normalize.symbolize_headers(nil) # => nil
73
+ # Normalize.symbolize_headers({}) # => {}
74
+ def self.symbolize_headers(headers)
75
+ # Handle nil input
76
+ return nil if headers.nil?
77
+
78
+ # Fast path for non-enumerable inputs
79
+ return {} unless headers.respond_to?(:each)
80
+
81
+ symbolized = {}
82
+
83
+ headers.each do |key, value|
84
+ next if key.nil?
85
+
86
+ # Convert key to symbol, replacing hyphens with underscores
87
+ symbolized_key = key.to_s.tr("-", "_").to_sym
88
+ symbolized[symbolized_key] = value
89
+ end
90
+
91
+ symbolized
92
+ end
93
+
61
94
  # Normalize a single HTTP header name
62
95
  #
63
96
  # @param header [String] Header name to normalize
data/lib/hooks/version.rb CHANGED
@@ -4,5 +4,5 @@
4
4
  module Hooks
5
5
  # Current version of the Hooks webhook framework
6
6
  # @return [String] The version string following semantic versioning
7
- VERSION = "0.0.4".freeze
7
+ VERSION = "0.0.6".freeze
8
8
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hooks-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - github