diff --git a/http/client.go b/http/client.go index 8105ccb6e9..6e5cc21276 100644 --- a/http/client.go +++ b/http/client.go @@ -29,7 +29,6 @@ import ( "github.com/sourcenetwork/defradb/client" "github.com/sourcenetwork/defradb/datastore" "github.com/sourcenetwork/defradb/event" - "github.com/sourcenetwork/defradb/internal/encryption" ) var _ client.DB = (*Client)(nil) @@ -350,6 +349,7 @@ func (c *Client) ExecRequest( result.GQL.Errors = []error{err} return result } + req, err := http.NewRequestWithContext(ctx, http.MethodPost, methodURL.String(), bytes.NewBuffer(body)) if err != nil { result.GQL.Errors = []error{err} @@ -357,10 +357,7 @@ func (c *Client) ExecRequest( } err = c.http.setDefaultHeaders(req) - encConf := encryption.GetContextConfig(ctx) - if encConf.HasValue() && encConf.Value().IsEncrypted { - req.Header.Set(DocEncryptionHeader, "1") - } + setDocEncryptionFlagIfNeeded(ctx, req) if err != nil { result.GQL.Errors = []error{err} diff --git a/http/client_collection.go b/http/client_collection.go index b1761366a7..8df094f5fc 100644 --- a/http/client_collection.go +++ b/http/client_collection.go @@ -79,7 +79,7 @@ func (c *Collection) Create( return err } - setDocEncryptionHeaderIfNeeded(ctx, req) + setDocEncryptionFlagIfNeeded(ctx, req) _, err = c.http.request(req) if err != nil { @@ -117,7 +117,7 @@ func (c *Collection) CreateMany( return err } - setDocEncryptionHeaderIfNeeded(ctx, req) + setDocEncryptionFlagIfNeeded(ctx, req) _, err = c.http.request(req) if err != nil { @@ -130,10 +130,12 @@ func (c *Collection) CreateMany( return nil } -func setDocEncryptionHeaderIfNeeded(ctx context.Context, req *http.Request) { +func setDocEncryptionFlagIfNeeded(ctx context.Context, req *http.Request) { encConf := encryption.GetContextConfig(ctx) if encConf.HasValue() && encConf.Value().IsEncrypted { - req.Header.Set(DocEncryptionHeader, "1") + q := req.URL.Query() + q.Set(docEncryptParam, "true") + req.URL.RawQuery = q.Encode() } } diff --git a/http/handler_collection.go b/http/handler_collection.go index 2d5111671f..412f486602 100644 --- a/http/handler_collection.go +++ b/http/handler_collection.go @@ -24,7 +24,7 @@ import ( "github.com/sourcenetwork/defradb/internal/encryption" ) -const DocEncryptionHeader = "EncryptDoc" +const docEncryptParam = "encrypt" type collectionHandler struct{} @@ -47,7 +47,7 @@ func (s *collectionHandler) Create(rw http.ResponseWriter, req *http.Request) { } ctx := req.Context() - if req.Header.Get(DocEncryptionHeader) == "1" { + if req.URL.Query().Get(docEncryptParam) == "true" { ctx = encryption.SetContextConfig(ctx, encryption.DocEncConfig{IsEncrypted: true}) }