mirror of
https://github.com/gotenberg/gotenberg.git
synced 2026-08-18 05:02:15 +01:00
refactoring: now detecting file type using filename from form data. Also, only one accepted content type
This commit is contained in:
@@ -42,18 +42,15 @@ func enforceContentLengthHandler(next http.Handler) http.Handler {
|
||||
}
|
||||
|
||||
// enforceContentTypeHandler checks if the "Content-Type" entry
|
||||
// from the request's header matches one of the allowed content types.
|
||||
// from the request's header matches the allowed content type.
|
||||
func enforceContentTypeHandler(next http.Handler) http.Handler {
|
||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
ct, err := ghttp.FindAuthorizedContentType(r.Header)
|
||||
if err != nil {
|
||||
if err := ghttp.CheckAuthorizedContentType(r.Header); err != nil {
|
||||
http.Error(w, err.Error(), http.StatusUnsupportedMediaType)
|
||||
logger.Error(err)
|
||||
return
|
||||
}
|
||||
|
||||
r = context.WithContentType(r, ct)
|
||||
|
||||
next.ServeHTTP(w, r)
|
||||
})
|
||||
}
|
||||
@@ -61,14 +58,7 @@ func enforceContentTypeHandler(next http.Handler) http.Handler {
|
||||
// convertHandler is in charge of converting the file(s) from the request to PDF.
|
||||
func convertHandler(next http.Handler) http.Handler {
|
||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
ct, err := context.GetContentType(r)
|
||||
if err != nil {
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
logger.Error(err)
|
||||
return
|
||||
}
|
||||
|
||||
c, err := converter.NewConverter(r, ct)
|
||||
c, err := converter.NewConverter(r)
|
||||
if err != nil {
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
logger.Error(err)
|
||||
|
||||
Reference in New Issue
Block a user