Skip to content

Commit

Permalink
feat: Add query params to websocket requests (#485)
Browse files Browse the repository at this point in the history
  • Loading branch information
tjholm authored Jul 12, 2023
2 parents f8ccb10 + 325d5d0 commit 2cb1307
Show file tree
Hide file tree
Showing 6 changed files with 184 additions and 119 deletions.
10 changes: 9 additions & 1 deletion cloud/aws/runtime/gateway/lambda.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,14 +98,22 @@ func (s *LambdaGateway) handleWebsocketEvent(ctx context.Context, evt events.API
return nil, fmt.Errorf("received websocket trigger from non-nitric API gateway")
}

queryParams := map[string]*v1.QueryValue{}
for k, v := range evt.QueryStringParameters {
queryParams[k] = &v1.QueryValue{
Value: []string{v},
}
}

req := &v1.TriggerRequest{
Data: []byte(evt.Body),
Context: &v1.TriggerRequest_Websocket{
Websocket: &v1.WebsocketTriggerContext{
ConnectionId: evt.RequestContext.ConnectionID,
Event: wsEvent,
// Get the API gateways nitric name
Socket: nitricName,
Socket: nitricName,
QueryParams: queryParams,
},
},
}
Expand Down
1 change: 1 addition & 0 deletions cloud/aws/runtime/gateway/lambda_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ var _ = Describe("Lambda", func() {
Socket: "test-api",
Event: v1.WebsocketEvent_Connect,
ConnectionId: "testing",
QueryParams: map[string]*v1.QueryValue{},
},
},
}).Return(&v1.TriggerResponse{
Expand Down
3 changes: 3 additions & 0 deletions contracts/proto/faas/v1/faas.proto
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,9 @@ message WebsocketTriggerContext {

// The connection this trigger came from
string connectionId = 3;

// The query params available in the connection request
map<string, QueryValue> query_params = 6;
}

// The worker has successfully processed a trigger
Expand Down
Loading

0 comments on commit 2cb1307

Please sign in to comment.