1
0
Fork 0
mirror of https://github.com/gocsaf/csaf.git synced 2025-12-22 11:55:40 +01:00

Add content-type error report test

This commit is contained in:
koplas 2025-03-10 12:02:44 +01:00
parent 3cfafa8263
commit 534d6f049f
2 changed files with 65 additions and 6 deletions

View file

@ -18,11 +18,12 @@ import (
// ProviderParams configures the test provider.
type ProviderParams struct {
URL string
EnableSha256 bool
EnableSha512 bool
ForbidSha256 bool
ForbidSha512 bool
URL string
EnableSha256 bool
EnableSha512 bool
ForbidSha256 bool
ForbidSha512 bool
JSONContentType string
}
// ProviderHandler returns a test provider handler with the specified configuration.
@ -35,6 +36,11 @@ func ProviderHandler(params *ProviderParams, directoryProvider bool) http.Handle
path += "simple-rolie-provider"
}
jsonContenType := "application/json"
if params.JSONContentType != "" {
jsonContenType = params.JSONContentType
}
path += r.URL.Path
if strings.HasSuffix(r.URL.Path, "/") {
@ -50,7 +56,7 @@ func ProviderHandler(params *ProviderParams, directoryProvider bool) http.Handle
case strings.HasSuffix(path, ".html"):
w.Header().Add("Content-Type", "text/html")
case strings.HasSuffix(path, ".json"):
w.Header().Add("Content-Type", "application/json")
w.Header().Add("Content-Type", jsonContenType)
case (strings.HasSuffix(path, ".sha256")) && params.ForbidSha256:
w.WriteHeader(http.StatusForbidden)
return