Skip to content

Commit

Permalink
Merge pull request #180 from chriskuehl/dont-use-multipart-for-fpb
Browse files Browse the repository at this point in the history
Don't use multipart form for fpb cli
  • Loading branch information
chriskuehl authored Nov 16, 2024
2 parents 9df4a09 + 2b75362 commit 410e595
Showing 1 changed file with 6 additions and 11 deletions.
17 changes: 6 additions & 11 deletions cli/fpb/fpb.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import (
"encoding/json"
"fmt"
"io"
"mime/multipart"
"net/http"
"net/url"
"os"
"regexp"
"runtime/debug"
Expand Down Expand Up @@ -105,9 +105,8 @@ Example usage:
path = args[0]
}

body := &bytes.Buffer{}
writer := multipart.NewWriter(body)
writer.WriteField("language", language)
form := url.Values{}
form.Set("language", language)

content := &bytes.Buffer{}
if path == "-" {
Expand Down Expand Up @@ -135,17 +134,13 @@ Example usage:
return fmt.Errorf("copying file: %w", err)
}
}
writer.WriteField("text", content.String())
form.Set("text", content.String())

if err := writer.Close(); err != nil {
return fmt.Errorf("closing writer: %w", err)
}

req, err := http.NewRequest("POST", server+"/paste?json", body)
req, err := http.NewRequest("POST", server+"/paste?json", strings.NewReader(form.Encode()))
if err != nil {
return fmt.Errorf("creating request: %w", err)
}
req.Header.Set("Content-Type", writer.FormDataContentType())
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
if creds != nil {
req.SetBasicAuth(creds.Username, creds.Password)
}
Expand Down

0 comments on commit 410e595

Please sign in to comment.