Skip to content

Commit

Permalink
Remove use of mimetype
Browse files Browse the repository at this point in the history
  • Loading branch information
Robi9 committed Jan 21, 2025
1 parent 9e7de1b commit 3e3792c
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 10 deletions.
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ require (
)

require (
github.com/pkg/errors v0.9.1
github.com/sirupsen/logrus v1.9.0
cloud.google.com/go/compute/metadata v0.6.0 // indirect
github.com/antchfx/xpath v1.3.3 // indirect
github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.6.7 // indirect
Expand Down Expand Up @@ -71,9 +69,11 @@ require (
github.com/naoina/toml v0.1.1 // indirect
github.com/nyaruka/null/v2 v2.0.3 // indirect
github.com/nyaruka/phonenumbers v1.4.3 // indirect
github.com/pkg/errors v0.9.1
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/samber/lo v1.47.0 // indirect
github.com/shopspring/decimal v1.4.0 // indirect
github.com/sirupsen/logrus v1.9.0
golang.org/x/crypto v0.31.0 // indirect
golang.org/x/exp v0.0.0-20241215155358-4a5509556b9e // indirect
golang.org/x/net v0.32.0 // indirect
Expand Down
1 change: 1 addition & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ github.com/shopspring/decimal v1.4.0/go.mod h1:gawqmDU56v4yIKSwfBSFip1HdCCXN8/+D
github.com/sirupsen/logrus v1.9.0 h1:trlNQbNUG3OdDrDil03MCb1H2o9nJ1x4/5LYw7byDE0=
github.com/sirupsen/logrus v1.9.0/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
Expand Down
11 changes: 3 additions & 8 deletions handlers/whatsapp_legacy/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ import (
"time"

"github.com/buger/jsonparser"
"github.com/gabriel-vasile/mimetype"
"github.com/gomodule/redigo/redis"
"github.com/nyaruka/courier"
"github.com/nyaruka/courier/backends/rapidpro"
"github.com/nyaruka/courier/handlers"
"github.com/nyaruka/courier/utils"
"github.com/nyaruka/gocommon/httpx"
"github.com/nyaruka/gocommon/i18n"
"github.com/nyaruka/gocommon/jsonx"
"github.com/nyaruka/gocommon/urns"
Expand Down Expand Up @@ -920,14 +920,9 @@ func (h *handler) fetchMediaID(msg courier.MsgOut, mediaURL string, clog *courie
return "", fmt.Errorf("error building request to media endpoint: %w", err)
}
setWhatsAppAuthHeader(&req.Header, msg.Channel())
mtype := http.DetectContentType(respBody)
mediaType, _ := httpx.DetectContentType(respBody)
req.Header.Add("Content-Type", mediaType)

if mtype != mimeType || mtype == "application/octet-stream" || mtype == "application/zip" {
mimeT := mimetype.Detect(respBody)
req.Header.Add("Content-Type", mimeT.String())
} else {
req.Header.Add("Content-Type", mtype)
}
resp, respBody, err = h.RequestHTTP(req, clog)
if err != nil || resp.StatusCode/100 != 2 {
failedMediaCache.Set(failKey, true, cache.DefaultExpiration)
Expand Down

0 comments on commit 3e3792c

Please sign in to comment.