Skip to content

Commit

Permalink
fix: Proto serialization for http FaaS requests.
Browse files Browse the repository at this point in the history
  • Loading branch information
tjholm committed Jun 12, 2021
1 parent a4cd436 commit f9ba60a
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions worker/faas_http_worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
pb "github.com/nitric-dev/membrane/interfaces/nitric/v1"
"github.com/nitric-dev/membrane/triggers"
"github.com/valyala/fasthttp"
"google.golang.org/protobuf/encoding/protojson"
)

// A Nitric HTTP worker
Expand Down Expand Up @@ -117,9 +118,7 @@ func (h *FaasHttpWorker) HandleHttpRequest(trigger *triggers.HttpRequest) (*trig
},
}

if jsonData, err := json.Marshal(triggerRequest); err != nil {
request := fasthttp.AcquireRequest()

if jsonData, err := protojson.Marshal(triggerRequest); err == nil {
request.Header.SetContentType("application/json")
request.SetBody(jsonData)
request.SetRequestURI(address)
Expand All @@ -132,7 +131,7 @@ func (h *FaasHttpWorker) HandleHttpRequest(trigger *triggers.HttpRequest) (*trig

// Response body should contain an instance of triggerResponse
var triggerResponse pb.TriggerResponse
err = json.Unmarshal(response.Body(), &triggerResponse)
err = protojson.Unmarshal(response.Body(), &triggerResponse)

if err != nil {
return nil, err
Expand Down Expand Up @@ -168,7 +167,6 @@ func NewFaasHttpWorker(address string) (*FaasHttpWorker, error) {
}
}
}

// Dial the provided address to ensure its availability
return &FaasHttpWorker{
address: address,
Expand Down

0 comments on commit f9ba60a

Please sign in to comment.