Skip to content

Commit

Permalink
update status code
Browse files Browse the repository at this point in the history
  • Loading branch information
gravityblast committed Oct 24, 2023
1 parent 5797e8a commit fd9bd98
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
5 changes: 2 additions & 3 deletions handlers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func TestPinJSONHandler(t *testing.T) {

resp := w.Result()

assert.Equal(t, 200, resp.StatusCode)
assert.Equal(t, 201, resp.StatusCode)
assert.Equal(t, "text/plain; charset=utf-8", resp.Header.Get("Content-Type"))

var responseBody PinJSONResponseBody
Expand Down Expand Up @@ -110,7 +110,6 @@ func TestPinFileHandler(t *testing.T) {

body := new(bytes.Buffer)
writer := multipart.NewWriter(body)
// writer.WriteField("file", "Uploaded content")

// Create the file part with an invalid file extension
h := make(textproto.MIMEHeader)
Expand All @@ -129,7 +128,7 @@ func TestPinFileHandler(t *testing.T) {

resp := w.Result()

assert.Equal(t, 200, resp.StatusCode)
assert.Equal(t, 201, resp.StatusCode)
assert.Equal(t, "text/plain; charset=utf-8", resp.Header.Get("Content-Type"))

var responseBody PinJSONResponseBody
Expand Down
4 changes: 4 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,9 @@ func handleUpload(w http.ResponseWriter, r *http.Request, content []byte) error
return err
}

w.Header().Add("Content-Type", "text/plain; charset=utf-8")
w.WriteHeader(http.StatusCreated)

// encode response body
err = json.NewEncoder(w).Encode(&PinJSONResponseBody{
IpfsHash: ipfsHash,
Expand Down Expand Up @@ -169,6 +172,7 @@ func pinFileHandler(w http.ResponseWriter, r *http.Request, _ httprouter.Params)
if err != nil {
handleError(w, err)
}

}

func authWrapper(next httprouter.Handle) httprouter.Handle {
Expand Down

0 comments on commit fd9bd98

Please sign in to comment.