Skip to content

Commit

Permalink
Allow parameterized application/json content types
Browse files Browse the repository at this point in the history
Signed-off-by: Appu Goundan <appu@google.com>
  • Loading branch information
loosebazooka committed Feb 4, 2022
1 parent 5c51127 commit 41e153e
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion pkg/api/ca.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"encoding/base64"
"encoding/json"
"fmt"
"mime"
"net/http"
"strings"

Expand Down Expand Up @@ -116,7 +117,15 @@ func (a *api) signingCert(w http.ResponseWriter, req *http.Request) {
handleFulcioAPIError(w, req, http.StatusMethodNotAllowed, err, err.Error())
return
}
if gotContentType, wantContentType := req.Header.Get("Content-Type"), "application/json"; gotContentType != wantContentType {

contentTypeHeader := req.Header.Get("Content-Type")
gotContentType, _, perr := mime.ParseMediaType(contentTypeHeader)
if perr != nil {
err := fmt.Errorf("could not parse Content-Type %q", contentTypeHeader)
handleFulcioAPIError(w, req, http.StatusUnsupportedMediaType, err, err.Error())
}
wantContentType := "application/json"
if gotContentType != wantContentType {
err := fmt.Errorf("signing cert handler must receive %q, got %q", wantContentType, gotContentType)
handleFulcioAPIError(w, req, http.StatusUnsupportedMediaType, err, err.Error())
return
Expand Down

0 comments on commit 41e153e

Please sign in to comment.