* all: Upgrade listenerutil dependency The new listenerutil implements http.Flusher, which is necessary for streaming responses from the grpc-gateway to work. * daemon/controller: Remove newline delimiter in streaming responses The default gRPC-Gateway HTTPBody marshaler uses newlines as a delimiter. This introduces newlines in our streamed responses. Wrapping the default marshaler lets us define a nil delimiter, which ensures our streaming responses are unaffected by the server side chunking.
27 lines
774 B
Go
27 lines
774 B
Go
// Copyright (c) HashiCorp, Inc.
|
|
// SPDX-License-Identifier: MPL-2.0
|
|
|
|
package handlers
|
|
|
|
import (
|
|
"github.com/grpc-ecosystem/grpc-gateway/v2/runtime"
|
|
"google.golang.org/protobuf/encoding/protojson"
|
|
)
|
|
|
|
// JSONMarshaler provides marshaler used for marshaling all proto as JSON
|
|
// in a format expected by the user facing controller API.
|
|
func JSONMarshaler() *runtime.JSONPb {
|
|
return &runtime.JSONPb{
|
|
MarshalOptions: protojson.MarshalOptions{
|
|
// Ensures the json marshaler uses the snake casing as defined in the proto field names.
|
|
UseProtoNames: true,
|
|
// Do not add fields set to zero value to json.
|
|
EmitUnpopulated: false,
|
|
},
|
|
UnmarshalOptions: protojson.UnmarshalOptions{
|
|
// Allows requests to contain unknown fields.
|
|
DiscardUnknown: true,
|
|
},
|
|
}
|
|
}
|