You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The `payload` parameter can be a Hash or a String. If the payload is a String, it will be parsed as JSON. If it is a Hash, it will be passed directly to the handler. The payload can contain any data that the webhook sender wants to send.
33
33
34
-
By default, the payload is parsed as JSON (if it can be) and then symbolized. This means that the keys in the payload will be converted to symbols. You can disable this auto-symbolization of the payload by setting the environment variable `HOOKS_SYMBOLIZE_PAYLOAD` to `false` or by setting the `symbolize_payload` option to `false` in the global configuration file.
34
+
The payload is parsed as JSON (if it can be) and returned as a pure Ruby hash with string keys, maintaining the original JSON structure. This ensures that the payload is always a valid JSON representation that can be easily serialized and processed.
35
35
36
-
**TL;DR**: The payload is almost always a Hash with symbolized keys, regardless of whether the original payload was a Hash or a JSON String.
36
+
**TL;DR**: The payload is almost always a Hash with string keys, regardless of whether the original payload was a Hash or a JSON String.
37
37
38
38
For example, if the client sends the following JSON payload:
39
39
@@ -50,24 +50,24 @@ It will be parsed and passed to the handler as:
50
50
51
51
```ruby
52
52
{
53
-
hello:"world",
54
-
foo: ["bar", "baz"],
55
-
truthy:true,
56
-
coffee: {is:"good"}
53
+
"hello" =>"world",
54
+
"foo" => ["bar", "baz"],
55
+
"truthy" =>true,
56
+
"coffee" => {"is" =>"good"}
57
57
}
58
58
```
59
59
60
60
### `headers` Parameter
61
61
62
62
The `headers` parameter is a Hash that contains the HTTP headers that were sent with the webhook request. It includes standard headers like `host`, `user-agent`, `accept`, and any custom headers that the webhook sender may have included.
63
63
64
-
By default, the headers are normalized (lowercased and trimmed) and then symbolized. This means that the keys in the headers will be converted to symbols, and any hyphens (`-`) in header names are converted to underscores (`_`). You can disable header symbolization by setting the environment variable `HOOKS_SYMBOLIZE_HEADERS` to `false` or by setting the `symbolize_headers` option to `false` in the global configuration file.
64
+
By default, the headers are normalized (lowercased and trimmed) but kept as string keys to maintain their JSON representation. Header keys are always strings, and any normalization simply ensures consistent formatting (lowercasing and trimming whitespace). You can disable header normalization by setting the environment variable `HOOKS_NORMALIZE_HEADERS` to `false` or by setting the `normalize_headers` option to `false` in the global configuration file.
65
65
66
-
**TL;DR**: The headers are almost always a Hash with symbolized keys, with hyphens converted to underscores.
66
+
**TL;DR**: The headers are always a Hash with string keys, optionally normalized for consistency.
67
67
68
68
For example, if the client sends the following headers:
69
69
70
-
```
70
+
```text
71
71
Host: hooks.example.com
72
72
User-Agent: foo-client/1.0
73
73
Accept: application/json, text/plain, */*
@@ -79,25 +79,23 @@ X-Forwarded-Proto: https
79
79
Authorization: Bearer <TOKEN>
80
80
```
81
81
82
-
They will be normalized and symbolized and passed to the handler as:
82
+
They will be normalized and passed to the handler as:
83
83
84
84
```ruby
85
85
{
86
-
host:"hooks.example.com",
87
-
user_agent:"foo-client/1.0",
88
-
accept:"application/json, text/plain, */*",
89
-
accept_encoding:"gzip, compress, deflate, br",
90
-
client_name:"foo",
91
-
x_forwarded_for:"<IP_ADDRESS>",
92
-
x_forwarded_host:"hooks.example.com",
93
-
x_forwarded_proto:"https",
94
-
authorization:"Bearer <TOKEN>"# a careful reminder that headers *can* contain sensitive information!
"authorization" =>"Bearer <TOKEN>"# a careful reminder that headers *can* contain sensitive information!
95
95
}
96
96
```
97
97
98
-
It should be noted that the `headers` parameter is a Hash with **symbolized keys** (not strings) by default. They are also normalized (lowercased and trimmed) to ensure consistency.
99
-
100
-
You can disable header symbolization by either setting the environment variable `HOOKS_SYMBOLIZE_HEADERS` to `false` or by setting the `symbolize_headers` option to `false` in the global configuration file.
98
+
It should be noted that the `headers` parameter is a Hash with **string keys** (not symbols). They are optionally normalized (lowercased and trimmed) to ensure consistency.
101
99
102
100
You can disable header normalization by either setting the environment variable `HOOKS_NORMALIZE_HEADERS` to `false` or by setting the `normalize_headers` option to `false` in the global configuration file.
0 commit comments