|
|
@ -15,42 +15,47 @@ const (
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
// ContentTypeRule defines a rule for content type determination
|
|
|
|
// ContentTypeRule defines a rule for content type determination
|
|
|
|
type ContentTypeRule struct {
|
|
|
|
type contentTypeRule struct {
|
|
|
|
Path string
|
|
|
|
path string
|
|
|
|
Method string
|
|
|
|
method string
|
|
|
|
ContentType string
|
|
|
|
contentType string
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
var contentTypeRules = []ContentTypeRule{
|
|
|
|
var contentTypeRules = []contentTypeRule{
|
|
|
|
{
|
|
|
|
{
|
|
|
|
Path: "/v1/snapshot",
|
|
|
|
path: "/v1/snapshot",
|
|
|
|
Method: http.MethodGet,
|
|
|
|
method: http.MethodGet,
|
|
|
|
ContentType: "application/x-gzip",
|
|
|
|
contentType: "application/x-gzip",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
{
|
|
|
|
Path: "/v1/snapshot",
|
|
|
|
path: "/v1/snapshot",
|
|
|
|
Method: http.MethodPut,
|
|
|
|
method: http.MethodPut,
|
|
|
|
ContentType: "application/octet-stream",
|
|
|
|
contentType: "application/octet-stream",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
{
|
|
|
|
Path: "/v1/kv",
|
|
|
|
path: "/v1/kv",
|
|
|
|
Method: http.MethodPut,
|
|
|
|
method: http.MethodPut,
|
|
|
|
ContentType: "application/octet-stream",
|
|
|
|
contentType: "application/octet-stream",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
{
|
|
|
|
Path: "/v1/kv",
|
|
|
|
path: "/v1/kv",
|
|
|
|
Method: http.MethodDelete,
|
|
|
|
method: http.MethodDelete,
|
|
|
|
ContentType: "",
|
|
|
|
contentType: "",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
{
|
|
|
|
Path: "/v1/kv",
|
|
|
|
path: "/v1/kv",
|
|
|
|
Method: http.MethodGet,
|
|
|
|
method: http.MethodGet,
|
|
|
|
ContentType: "",
|
|
|
|
contentType: "",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
{
|
|
|
|
Path: "/v1/event/fire",
|
|
|
|
path: "/v1/event/fire",
|
|
|
|
Method: http.MethodPut,
|
|
|
|
method: http.MethodPut,
|
|
|
|
ContentType: "application/octet-stream",
|
|
|
|
contentType: "application/octet-stream",
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
path: "/ui",
|
|
|
|
|
|
|
|
method: http.MethodGet,
|
|
|
|
|
|
|
|
contentType: PlainContentType,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -72,7 +77,7 @@ func DetermineContentType(req *http.Request) string {
|
|
|
|
// Check against defined endpoint and required content type rules
|
|
|
|
// Check against defined endpoint and required content type rules
|
|
|
|
for _, rule := range contentTypeRules {
|
|
|
|
for _, rule := range contentTypeRules {
|
|
|
|
if matchesRule(req, rule) {
|
|
|
|
if matchesRule(req, rule) {
|
|
|
|
return rule.ContentType
|
|
|
|
return rule.contentType
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -81,9 +86,9 @@ func DetermineContentType(req *http.Request) string {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// matchesRule checks if a request matches a content type rule
|
|
|
|
// matchesRule checks if a request matches a content type rule
|
|
|
|
func matchesRule(req *http.Request, rule ContentTypeRule) bool {
|
|
|
|
func matchesRule(req *http.Request, rule contentTypeRule) bool {
|
|
|
|
return strings.HasPrefix(req.URL.Path, rule.Path) &&
|
|
|
|
return strings.HasPrefix(req.URL.Path, rule.path) &&
|
|
|
|
(rule.Method == "" || req.Method == rule.Method)
|
|
|
|
(rule.method == "" || req.Method == rule.method)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// isIndexPage checks if the request is for the index page
|
|
|
|
// isIndexPage checks if the request is for the index page
|
|
|
|