diff --git a/client/deployment_get.go b/client/deployment_get.go index 1e8ab81f..eb63e79c 100644 --- a/client/deployment_get.go +++ b/client/deployment_get.go @@ -4,7 +4,6 @@ import ( "context" "fmt" "net/http" - "strings" "github.com/hashicorp/terraform-plugin-log/tflog" ) @@ -19,7 +18,7 @@ func (c *Client) GetDeployment(ctx context.Context, deploymentID, teamID string) ctx, "GET", url, - strings.NewReader(""), + nil, ) if err != nil { return r, err diff --git a/client/environment_variables_delete.go b/client/environment_variables_delete.go index b67048ab..8966f6d2 100644 --- a/client/environment_variables_delete.go +++ b/client/environment_variables_delete.go @@ -4,7 +4,6 @@ import ( "context" "fmt" "net/http" - "strings" "github.com/hashicorp/terraform-plugin-log/tflog" ) @@ -19,7 +18,7 @@ func (c *Client) DeleteEnvironmentVariable(ctx context.Context, projectID, teamI ctx, "DELETE", url, - strings.NewReader(""), + nil, ) if err != nil { return err diff --git a/client/environment_variables_get.go b/client/environment_variables_get.go index 5e48bfdb..c082b0ad 100644 --- a/client/environment_variables_get.go +++ b/client/environment_variables_get.go @@ -4,7 +4,6 @@ import ( "context" "fmt" "net/http" - "strings" "github.com/hashicorp/terraform-plugin-log/tflog" ) @@ -18,7 +17,7 @@ func (c *Client) getEnvironmentVariables(ctx context.Context, projectID, teamID ctx, "GET", url, - strings.NewReader(""), + nil, ) if err != nil { return nil, err diff --git a/client/file_create.go b/client/file_create.go index e39e4d55..6f42af80 100644 --- a/client/file_create.go +++ b/client/file_create.go @@ -23,6 +23,7 @@ func (c *Client) CreateFile(ctx context.Context, filename, sha, content string) } req.Header.Add("x-vercel-digest", sha) + req.Header.Set("Content-Type", "application/octet-stream") tflog.Trace(ctx, "uploading file", map[string]interface{}{ "url": url, diff --git a/client/project_delete.go b/client/project_delete.go index cc475629..a1f3b94c 100644 --- a/client/project_delete.go +++ b/client/project_delete.go @@ -4,7 +4,6 @@ import ( "context" "fmt" "net/http" - "strings" "github.com/hashicorp/terraform-plugin-log/tflog" ) @@ -20,7 +19,7 @@ func (c *Client) DeleteProject(ctx context.Context, projectID, teamID string) er ctx, "DELETE", url, - strings.NewReader(""), + nil, ) if err != nil { return err diff --git a/client/project_domain_delete.go b/client/project_domain_delete.go index 576aaa65..cf89ba03 100644 --- a/client/project_domain_delete.go +++ b/client/project_domain_delete.go @@ -4,7 +4,6 @@ import ( "context" "fmt" "net/http" - "strings" "github.com/hashicorp/terraform-plugin-log/tflog" ) @@ -20,7 +19,7 @@ func (c *Client) DeleteProjectDomain(ctx context.Context, projectID, domain, tea ctx, "DELETE", url, - strings.NewReader(""), + nil, ) if err != nil { return err diff --git a/client/project_domain_get.go b/client/project_domain_get.go index 4793cd68..3cb2d863 100644 --- a/client/project_domain_get.go +++ b/client/project_domain_get.go @@ -4,7 +4,6 @@ import ( "context" "fmt" "net/http" - "strings" "github.com/hashicorp/terraform-plugin-log/tflog" ) @@ -30,7 +29,7 @@ func (c *Client) GetProjectDomain(ctx context.Context, projectID, domain, teamID ctx, "GET", url, - strings.NewReader(""), + nil, ) if err != nil { return r, err diff --git a/client/project_get.go b/client/project_get.go index 9b7bd1e5..26ff4b23 100644 --- a/client/project_get.go +++ b/client/project_get.go @@ -4,7 +4,6 @@ import ( "context" "fmt" "net/http" - "strings" "github.com/hashicorp/terraform-plugin-log/tflog" ) @@ -77,7 +76,7 @@ func (c *Client) GetProject(ctx context.Context, projectID, teamID string) (r Pr ctx, "GET", url, - strings.NewReader(""), + nil, ) if err != nil { return r, err diff --git a/client/project_list.go b/client/project_list.go index 56ef7b54..fd7aab48 100644 --- a/client/project_list.go +++ b/client/project_list.go @@ -4,7 +4,6 @@ import ( "context" "fmt" "net/http" - "strings" "github.com/hashicorp/terraform-plugin-log/tflog" ) @@ -20,7 +19,7 @@ func (c *Client) ListProjects(ctx context.Context, teamID string) (r []ProjectRe ctx, "GET", url, - strings.NewReader(""), + nil, ) if err != nil { return r, err diff --git a/client/request.go b/client/request.go index e678b1b6..1a13f505 100644 --- a/client/request.go +++ b/client/request.go @@ -22,10 +22,15 @@ func (e APIError) Error() string { // doRequest is a helper function for consistently requesting data from vercel. // This manages: +// - Setting the default Content-Type for requests with a body // - Authorization via the Bearer token // - Converting error responses into an inspectable type // - Unmarshaling responses func (c *Client) doRequest(req *http.Request, v interface{}) error { + if req.Body != nil && req.Header.Get("Content-Type") == "" { + req.Header.Set("Content-Type", "application/json") + } + req.Header.Add("Authorization", fmt.Sprintf("Bearer %s", c.token)) resp, err := c.http().Do(req) if err != nil { diff --git a/client/team_delete.go b/client/team_delete.go index bcb01ec6..163a7cb0 100644 --- a/client/team_delete.go +++ b/client/team_delete.go @@ -4,7 +4,6 @@ import ( "context" "fmt" "net/http" - "strings" "github.com/hashicorp/terraform-plugin-log/tflog" ) @@ -16,7 +15,7 @@ func (c *Client) DeleteTeam(ctx context.Context, teamID string) error { ctx, "DELETE", url, - strings.NewReader(""), + nil, ) if err != nil { return err diff --git a/client/team_get.go b/client/team_get.go index 82626cf9..1503f29d 100644 --- a/client/team_get.go +++ b/client/team_get.go @@ -4,7 +4,6 @@ import ( "context" "fmt" "net/http" - "strings" "github.com/hashicorp/terraform-plugin-log/tflog" ) @@ -21,7 +20,7 @@ func (c *Client) GetTeam(ctx context.Context, teamID, slug string) (r TeamRespon ctx, "GET", url, - strings.NewReader(""), + nil, ) if err != nil { return r, err