Skip to content

Commit

Permalink
Add GZIP Encoding Support in Webhook Input and Relax Content-Type Fil…
Browse files Browse the repository at this point in the history
…ter (#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
  • Loading branch information
ricky-galvao authored Apr 26, 2024
1 parent 758ef51 commit 60eadaa
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v0.18.3
v0.18.4
2 changes: 1 addition & 1 deletion deploy/terraform/aws/lambda/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ variable "buz_image_repo" {
variable "buz_version" {
description = "The version of Buz to run."
type = string
default = "v0.18.3"
default = "v0.18.4"
}

variable "buz_lambda_memory_limit" {
Expand Down
2 changes: 1 addition & 1 deletion deploy/terraform/gcp/cloud_run/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ variable "buz_domain" {
variable "buz_version" {
description = "The version of Buz to run."
type = string
default = "v0.18.3"
default = "v0.18.4"
}

variable "buz_service_timeout_seconds" {
Expand Down
2 changes: 1 addition & 1 deletion examples/quickstart/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ x-dependency:
services:
buz:
container_name: buz
image: ghcr.io/silverton-io/buz:v0.18.3
image: ghcr.io/silverton-io/buz:v0.18.4
volumes:
- type: bind
source: ./buz/quickstart.conf.yml
Expand Down
17 changes: 17 additions & 0 deletions pkg/protocol/webhook/envelopeBuilder.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
package webhook

import (
"bytes"
"compress/gzip"
"io"

"github.com/gin-gonic/gin"
Expand All @@ -23,6 +25,21 @@ func buildEnvelopesFromRequest(c *gin.Context, conf *config.Config, m *meta.Coll
log.Error().Err(err).Msg("🔴 could not read request body")
return envelopes
}
// If the request body is gzipped, decompress it
if c.GetHeader("Content-Encoding") == "gzip" {
log.Debug().Msg("🟢 Request body is gzip encoded - attempting to decompress.")
reader, err := gzip.NewReader(bytes.NewReader(reqBody))
if err != nil {
log.Error().Err(err).Msg("🔴 could not decompress gzipped request body")
return envelopes
}
defer reader.Close()
reqBody, err = io.ReadAll(reader)
if err != nil {
log.Error().Err(err).Msg("🔴 could not read decompressed gzipped request body")
return envelopes
}
}
for _, e := range gjson.ParseBytes(reqBody).Array() {
n := envelope.NewEnvelope(conf.App)
contexts := envelope.BuildContextsFromRequest(c)
Expand Down
3 changes: 2 additions & 1 deletion pkg/protocol/webhook/input.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package webhook

import (
"net/http"
"strings"

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

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

0 comments on commit 60eadaa

Please sign in to comment.