Skip to content

Commit

Permalink
feat: Support non-authenticated calls (#91)
Browse files Browse the repository at this point in the history
Closes #39
  • Loading branch information
yitsushi authored Mar 21, 2022
1 parent 2f14a00 commit 640082c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
4 changes: 3 additions & 1 deletion core/json_request.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ func (r JSONRequest) ToBody(token string) ([]byte, string, error) {
return requestBody, jsonContentType, err
}

repack["i"] = token
if token != "" {
repack["i"] = token
}

content, err := json.Marshal(repack)

Expand Down
12 changes: 7 additions & 5 deletions core/multipart_request.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,15 @@ func (r *MultipartRequest) ToBody(token string) ([]byte, string, error) {
body := bytes.Buffer{}
writer := multipart.NewWriter(&body)

tokenPart, _ := writer.CreateFormField("i")
if token != "" {
tokenPart, _ := writer.CreateFormField("i")

_, err := tokenPart.Write([]byte(token))
if err != nil {
writer.Close()
_, err := tokenPart.Write([]byte(token))
if err != nil {
writer.Close()

return body.Bytes(), "", err
return body.Bytes(), "", err
}
}

fields := parseMultipartFields(r.Request)
Expand Down

0 comments on commit 640082c

Please sign in to comment.