这是indexloc提供的服务,不要输入任何密码
Skip to content

Adding Content-Type headers to POST and PATCH requests #23

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Apr 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions client/deployment_get.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"context"
"fmt"
"net/http"
"strings"

"github.com/hashicorp/terraform-plugin-log/tflog"
)
Expand All @@ -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
Expand Down
3 changes: 1 addition & 2 deletions client/environment_variables_delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"context"
"fmt"
"net/http"
"strings"

"github.com/hashicorp/terraform-plugin-log/tflog"
)
Expand All @@ -19,7 +18,7 @@ func (c *Client) DeleteEnvironmentVariable(ctx context.Context, projectID, teamI
ctx,
"DELETE",
url,
strings.NewReader(""),
nil,
)
if err != nil {
return err
Expand Down
3 changes: 1 addition & 2 deletions client/environment_variables_get.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"context"
"fmt"
"net/http"
"strings"

"github.com/hashicorp/terraform-plugin-log/tflog"
)
Expand All @@ -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
Expand Down
1 change: 1 addition & 0 deletions client/file_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
3 changes: 1 addition & 2 deletions client/project_delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"context"
"fmt"
"net/http"
"strings"

"github.com/hashicorp/terraform-plugin-log/tflog"
)
Expand All @@ -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
Expand Down
3 changes: 1 addition & 2 deletions client/project_domain_delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"context"
"fmt"
"net/http"
"strings"

"github.com/hashicorp/terraform-plugin-log/tflog"
)
Expand All @@ -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
Expand Down
3 changes: 1 addition & 2 deletions client/project_domain_get.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"context"
"fmt"
"net/http"
"strings"

"github.com/hashicorp/terraform-plugin-log/tflog"
)
Expand All @@ -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
Expand Down
3 changes: 1 addition & 2 deletions client/project_get.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"context"
"fmt"
"net/http"
"strings"

"github.com/hashicorp/terraform-plugin-log/tflog"
)
Expand Down Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions client/project_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"context"
"fmt"
"net/http"
"strings"

"github.com/hashicorp/terraform-plugin-log/tflog"
)
Expand All @@ -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
Expand Down
5 changes: 5 additions & 0 deletions client/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
3 changes: 1 addition & 2 deletions client/team_delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"context"
"fmt"
"net/http"
"strings"

"github.com/hashicorp/terraform-plugin-log/tflog"
)
Expand All @@ -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
Expand Down
3 changes: 1 addition & 2 deletions client/team_get.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"context"
"fmt"
"net/http"
"strings"

"github.com/hashicorp/terraform-plugin-log/tflog"
)
Expand All @@ -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
Expand Down