1
0
Fork 0
mirror of https://github.com/sourcegraph/jsonrpc2.git synced 2026-06-16 04:04:56 +02:00

Ensure that SetExtraField cannot be used to overwrite another field

This commit is contained in:
lhchavez 2021-07-28 13:22:26 +00:00
parent 83d34e6888
commit 4e1e529bef

View file

@ -179,6 +179,10 @@ func (r *Request) SetMeta(v interface{}) error {
// JSON representation of the request, as a way to add arbitrary extensions to
// JSON RPC 2.0. If JSON marshaling fails, it returns an error.
func (r *Request) SetExtraField(name string, v interface{}) error {
switch name {
case "id", "jsonrpc", "meta", "method", "params":
return fmt.Errorf("invalid extra field %q", name)
}
r.ExtraFields = append(r.ExtraFields, RequestField{
Name: name,
Value: v,