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
Copy file name to clipboardExpand all lines: docs/handler_plugins.md
+34-16Lines changed: 34 additions & 16 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -15,8 +15,8 @@ Handler plugins are Ruby classes that extend the `Hooks::Plugins::Handlers::Base
15
15
classExample < Hooks::Plugins::Handlers::Base
16
16
# Process a webhook payload
17
17
#
18
-
#@parampayload[Hash, String] webhook payload
19
-
#@paramheaders[Hash<String, String>] HTTP headers
18
+
#@parampayload[Hash, String] webhook payload (symbolized keys by default)
19
+
#@paramheaders[Hash] HTTP headers (symbolized keys by default)
20
20
#@paramconfig[Hash] Endpoint configuration
21
21
#@return[Hash] Response data
22
22
defcall(payload:, headers:, config:)
@@ -61,27 +61,45 @@ It will be parsed and passed to the handler as:
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
-
Here is an example of what the `headers` parameter might look like:
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.
65
+
66
+
**TL;DR**: The headers are almost always a Hash with symbolized keys, with hyphens converted to underscores.
67
+
68
+
For example, if the client sends the following headers:
69
+
70
+
```
71
+
Host: hooks.example.com
72
+
User-Agent: foo-client/1.0
73
+
Accept: application/json, text/plain, */*
74
+
Accept-Encoding: gzip, compress, deflate, br
75
+
Client-Name: foo
76
+
X-Forwarded-For: <IP_ADDRESS>
77
+
X-Forwarded-Host: hooks.example.com
78
+
X-Forwarded-Proto: https
79
+
Authorization: Bearer <TOKEN>
80
+
```
81
+
82
+
They will be normalized and symbolized and passed to the handler as:
"Authorization" => "Bearer <TOKEN>"# a careful reminder that headers *can* contain sensitive information!
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!
79
95
}
80
96
```
81
97
82
-
It should be noted that the `headers` parameter is a Hash with **String keys** (not symbols). They are also normalized (lowercased and trimmed) to ensure consistency.
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.
83
101
84
-
You can disable this 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.
102
+
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