Skip to content

Commit 60eadaa

Browse files
authored
Add GZIP Encoding Support in Webhook Input and Relax Content-Type Filter (#590)
* Relax Content-Type expectation and bump version to 0.18.3 * Add GZIP Encoding Support in Webhook Input and Relax Content-Type Filter * Fix defer placement
1 parent 758ef51 commit 60eadaa

File tree

6 files changed

+23
-5
lines changed

6 files changed

+23
-5
lines changed

.VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
v0.18.3
1+
v0.18.4

deploy/terraform/aws/lambda/variables.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ variable "buz_image_repo" {
4141
variable "buz_version" {
4242
description = "The version of Buz to run."
4343
type = string
44-
default = "v0.18.3"
44+
default = "v0.18.4"
4545
}
4646

4747
variable "buz_lambda_memory_limit" {

deploy/terraform/gcp/cloud_run/variables.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ variable "buz_domain" {
2828
variable "buz_version" {
2929
description = "The version of Buz to run."
3030
type = string
31-
default = "v0.18.3"
31+
default = "v0.18.4"
3232
}
3333

3434
variable "buz_service_timeout_seconds" {

examples/quickstart/docker-compose.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ x-dependency:
2020
services:
2121
buz:
2222
container_name: buz
23-
image: ghcr.io/silverton-io/buz:v0.18.3
23+
image: ghcr.io/silverton-io/buz:v0.18.4
2424
volumes:
2525
- type: bind
2626
source: ./buz/quickstart.conf.yml

pkg/protocol/webhook/envelopeBuilder.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
package webhook
66

77
import (
8+
"bytes"
9+
"compress/gzip"
810
"io"
911

1012
"github.com/gin-gonic/gin"
@@ -23,6 +25,21 @@ func buildEnvelopesFromRequest(c *gin.Context, conf *config.Config, m *meta.Coll
2325
log.Error().Err(err).Msg("🔴 could not read request body")
2426
return envelopes
2527
}
28+
// If the request body is gzipped, decompress it
29+
if c.GetHeader("Content-Encoding") == "gzip" {
30+
log.Debug().Msg("🟢 Request body is gzip encoded - attempting to decompress.")
31+
reader, err := gzip.NewReader(bytes.NewReader(reqBody))
32+
if err != nil {
33+
log.Error().Err(err).Msg("🔴 could not decompress gzipped request body")
34+
return envelopes
35+
}
36+
defer reader.Close()
37+
reqBody, err = io.ReadAll(reader)
38+
if err != nil {
39+
log.Error().Err(err).Msg("🔴 could not read decompressed gzipped request body")
40+
return envelopes
41+
}
42+
}
2643
for _, e := range gjson.ParseBytes(reqBody).Array() {
2744
n := envelope.NewEnvelope(conf.App)
2845
contexts := envelope.BuildContextsFromRequest(c)

pkg/protocol/webhook/input.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ package webhook
66

77
import (
88
"net/http"
9+
"strings"
910

1011
"github.com/gin-gonic/gin"
1112
"github.com/rs/zerolog/log"
@@ -34,7 +35,7 @@ func (i *WebhookInput) Initialize(routerGroup *gin.RouterGroup, manifold *manifo
3435

3536
func (i *WebhookInput) Handler(m manifold.Manifold, conf config.Config, metadata *meta.CollectorMeta) gin.HandlerFunc {
3637
fn := func(c *gin.Context) {
37-
if c.ContentType() == "application/json" || c.ContentType() == "text/html" {
38+
if c.ContentType() == "application/json" || strings.HasPrefix(c.ContentType(), "text/") {
3839
envelopes := i.EnvelopeBuilder(c, &conf, metadata)
3940
err := m.Enqueue(envelopes)
4041
if err != nil {

0 commit comments

Comments
 (0)