all: consistently return application/json content-type without charset=utf-8

The `application/json` content-type has utf-8 encoding by default.
See https://stackoverflow.com/questions/9254891/what-does-content-type-application-json-charset-utf-8-really-mean

Updates https://github.com/VictoriaMetrics/VictoriaMetrics/pull/897
This commit is contained in:
Aliaksandr Valialkin 2021-11-09 18:03:50 +02:00
parent 802f05f73f
commit e5ac9d8e57
No known key found for this signature in database
GPG key ID: A72BEC6CD3D0DED1
11 changed files with 45 additions and 45 deletions

View file

@ -236,26 +236,26 @@ func requestHandler(w http.ResponseWriter, r *http.Request) bool {
return true return true
} }
// See https://docs.datadoghq.com/api/latest/metrics/#submit-metrics // See https://docs.datadoghq.com/api/latest/metrics/#submit-metrics
w.Header().Set("Content-Type", "application/json; charset=utf-8") w.Header().Set("Content-Type", "application/json")
w.WriteHeader(202) w.WriteHeader(202)
fmt.Fprintf(w, `{"status":"ok"}`) fmt.Fprintf(w, `{"status":"ok"}`)
return true return true
case "/datadog/api/v1/validate": case "/datadog/api/v1/validate":
datadogValidateRequests.Inc() datadogValidateRequests.Inc()
// See https://docs.datadoghq.com/api/latest/authentication/#validate-api-key // See https://docs.datadoghq.com/api/latest/authentication/#validate-api-key
w.Header().Set("Content-Type", "application/json; charset=utf-8") w.Header().Set("Content-Type", "application/json")
fmt.Fprintf(w, `{"valid":true}`) fmt.Fprintf(w, `{"valid":true}`)
return true return true
case "/datadog/api/v1/check_run": case "/datadog/api/v1/check_run":
datadogCheckRunRequests.Inc() datadogCheckRunRequests.Inc()
// See https://docs.datadoghq.com/api/latest/service-checks/#submit-a-service-check // See https://docs.datadoghq.com/api/latest/service-checks/#submit-a-service-check
w.Header().Set("Content-Type", "application/json; charset=utf-8") w.Header().Set("Content-Type", "application/json")
w.WriteHeader(202) w.WriteHeader(202)
fmt.Fprintf(w, `{"status":"ok"}`) fmt.Fprintf(w, `{"status":"ok"}`)
return true return true
case "/datadog/intake/": case "/datadog/intake/":
datadogIntakeRequests.Inc() datadogIntakeRequests.Inc()
w.Header().Set("Content-Type", "application/json; charset=utf-8") w.Header().Set("Content-Type", "application/json")
fmt.Fprintf(w, `{}`) fmt.Fprintf(w, `{}`)
return true return true
case "/targets": case "/targets":
@ -277,7 +277,7 @@ func requestHandler(w http.ResponseWriter, r *http.Request) bool {
return true return true
case "/api/v1/targets": case "/api/v1/targets":
promscrapeAPIV1TargetsRequests.Inc() promscrapeAPIV1TargetsRequests.Inc()
w.Header().Set("Content-Type", "application/json; charset=utf-8") w.Header().Set("Content-Type", "application/json")
state := r.FormValue("state") state := r.FormValue("state")
promscrape.WriteAPIV1Targets(w, state) promscrape.WriteAPIV1Targets(w, state)
return true return true
@ -391,19 +391,19 @@ func processMultitenantRequest(w http.ResponseWriter, r *http.Request, path stri
case "datadog/api/v1/validate": case "datadog/api/v1/validate":
datadogValidateRequests.Inc() datadogValidateRequests.Inc()
// See https://docs.datadoghq.com/api/latest/authentication/#validate-api-key // See https://docs.datadoghq.com/api/latest/authentication/#validate-api-key
w.Header().Set("Content-Type", "application/json; charset=utf-8") w.Header().Set("Content-Type", "application/json")
fmt.Fprintf(w, `{"valid":true}`) fmt.Fprintf(w, `{"valid":true}`)
return true return true
case "datadog/api/v1/check_run": case "datadog/api/v1/check_run":
datadogCheckRunRequests.Inc() datadogCheckRunRequests.Inc()
// See https://docs.datadoghq.com/api/latest/service-checks/#submit-a-service-check // See https://docs.datadoghq.com/api/latest/service-checks/#submit-a-service-check
w.Header().Set("Content-Type", "application/json; charset=utf-8") w.Header().Set("Content-Type", "application/json")
w.WriteHeader(202) w.WriteHeader(202)
fmt.Fprintf(w, `{"status":"ok"}`) fmt.Fprintf(w, `{"status":"ok"}`)
return true return true
case "datadog/intake/": case "datadog/intake/":
datadogIntakeRequests.Inc() datadogIntakeRequests.Inc()
w.Header().Set("Content-Type", "application/json; charset=utf-8") w.Header().Set("Content-Type", "application/json")
fmt.Fprintf(w, `{}`) fmt.Fprintf(w, `{}`)
return true return true
default: default:

View file

@ -150,7 +150,7 @@ func (s *VMStorage) newRequestPOST() (*http.Request, error) {
if err != nil { if err != nil {
return nil, err return nil, err
} }
req.Header.Set("Content-Type", "application/json; charset=utf-8") req.Header.Set("Content-Type", "application/json")
if s.authCfg != nil { if s.authCfg != nil {
if auth := s.authCfg.GetAuthHeader(); auth != "" { if auth := s.authCfg.GetAuthHeader(); auth != "" {
req.Header.Set("Authorization", auth) req.Header.Set("Authorization", auth)

View file

@ -32,7 +32,7 @@ func (am *AlertManager) Send(ctx context.Context, alerts []Alert) error {
if err != nil { if err != nil {
return err return err
} }
req.Header.Set("Content-Type", "application/json; charset=utf-8") req.Header.Set("Content-Type", "application/json")
req = req.WithContext(ctx) req = req.WithContext(ctx)
if am.basicAuthPass != "" { if am.basicAuthPass != "" {
req.SetBasicAuth(am.basicAuthUser, am.basicAuthPass) req.SetBasicAuth(am.basicAuthUser, am.basicAuthPass)

View file

@ -68,7 +68,7 @@ func (rh *requestHandler) handler(w http.ResponseWriter, r *http.Request) bool {
httpserver.Errorf(w, r, "%s", err) httpserver.Errorf(w, r, "%s", err)
return true return true
} }
w.Header().Set("Content-Type", "application/json; charset=utf-8") w.Header().Set("Content-Type", "application/json")
w.Write(data) w.Write(data)
return true return true
case "/api/v1/alerts": case "/api/v1/alerts":
@ -77,7 +77,7 @@ func (rh *requestHandler) handler(w http.ResponseWriter, r *http.Request) bool {
httpserver.Errorf(w, r, "%s", err) httpserver.Errorf(w, r, "%s", err)
return true return true
} }
w.Header().Set("Content-Type", "application/json; charset=utf-8") w.Header().Set("Content-Type", "application/json")
w.Write(data) w.Write(data)
return true return true
case "/-/reload": case "/-/reload":
@ -102,7 +102,7 @@ func (rh *requestHandler) handler(w http.ResponseWriter, r *http.Request) bool {
httpserver.Errorf(w, r, "failed to marshal alert: %s", err) httpserver.Errorf(w, r, "failed to marshal alert: %s", err)
return true return true
} }
w.Header().Set("Content-Type", "application/json; charset=utf-8") w.Header().Set("Content-Type", "application/json")
w.Write(data) w.Write(data)
return true return true
} }

View file

@ -165,26 +165,26 @@ func RequestHandler(w http.ResponseWriter, r *http.Request) bool {
return true return true
} }
// See https://docs.datadoghq.com/api/latest/metrics/#submit-metrics // See https://docs.datadoghq.com/api/latest/metrics/#submit-metrics
w.Header().Set("Content-Type", "application/json; charset=utf-8") w.Header().Set("Content-Type", "application/json")
w.WriteHeader(202) w.WriteHeader(202)
fmt.Fprintf(w, `{"status":"ok"}`) fmt.Fprintf(w, `{"status":"ok"}`)
return true return true
case "/datadog/api/v1/validate": case "/datadog/api/v1/validate":
datadogValidateRequests.Inc() datadogValidateRequests.Inc()
// See https://docs.datadoghq.com/api/latest/authentication/#validate-api-key // See https://docs.datadoghq.com/api/latest/authentication/#validate-api-key
w.Header().Set("Content-Type", "application/json; charset=utf-8") w.Header().Set("Content-Type", "application/json")
fmt.Fprintf(w, `{"valid":true}`) fmt.Fprintf(w, `{"valid":true}`)
return true return true
case "/datadog/api/v1/check_run": case "/datadog/api/v1/check_run":
datadogCheckRunRequests.Inc() datadogCheckRunRequests.Inc()
// See https://docs.datadoghq.com/api/latest/service-checks/#submit-a-service-check // See https://docs.datadoghq.com/api/latest/service-checks/#submit-a-service-check
w.Header().Set("Content-Type", "application/json; charset=utf-8") w.Header().Set("Content-Type", "application/json")
w.WriteHeader(202) w.WriteHeader(202)
fmt.Fprintf(w, `{"status":"ok"}`) fmt.Fprintf(w, `{"status":"ok"}`)
return true return true
case "/datadog/intake/": case "/datadog/intake/":
datadogIntakeRequests.Inc() datadogIntakeRequests.Inc()
w.Header().Set("Content-Type", "application/json; charset=utf-8") w.Header().Set("Content-Type", "application/json")
fmt.Fprintf(w, `{}`) fmt.Fprintf(w, `{}`)
return true return true
case "/prometheus/targets", "/targets": case "/prometheus/targets", "/targets":
@ -193,7 +193,7 @@ func RequestHandler(w http.ResponseWriter, r *http.Request) bool {
return true return true
case "/prometheus/api/v1/targets", "/api/v1/targets": case "/prometheus/api/v1/targets", "/api/v1/targets":
promscrapeAPIV1TargetsRequests.Inc() promscrapeAPIV1TargetsRequests.Inc()
w.Header().Set("Content-Type", "application/json; charset=utf-8") w.Header().Set("Content-Type", "application/json")
state := r.FormValue("state") state := r.FormValue("state")
promscrape.WriteAPIV1Targets(w, state) promscrape.WriteAPIV1Targets(w, state)
return true return true

View file

@ -456,7 +456,7 @@ const maxRegexpCacheSize = 10000
func getContentType(jsonp string) string { func getContentType(jsonp string) string {
if jsonp == "" { if jsonp == "" {
return "application/json; charset=utf-8" return "application/json"
} }
return "text/javascript; charset=utf-8" return "text/javascript; charset=utf-8"
} }

View file

@ -62,7 +62,7 @@ func TagsDelSeriesHandler(startTime time.Time, w http.ResponseWriter, r *http.Re
totalDeleted += n totalDeleted += n
} }
w.Header().Set("Content-Type", "application/json; charset=utf-8") w.Header().Set("Content-Type", "application/json")
if totalDeleted > 0 { if totalDeleted > 0 {
fmt.Fprintf(w, "true") fmt.Fprintf(w, "true")
} else { } else {
@ -141,7 +141,7 @@ func registerMetrics(startTime time.Time, w http.ResponseWriter, r *http.Request
// Return response // Return response
contentType := "text/plain; charset=utf-8" contentType := "text/plain; charset=utf-8"
if isJSONResponse { if isJSONResponse {
contentType = "application/json; charset=utf-8" contentType = "application/json"
} }
w.Header().Set("Content-Type", contentType) w.Header().Set("Content-Type", contentType)
WriteTagsTagMultiSeriesResponse(w, canonicalPaths, isJSONResponse) WriteTagsTagMultiSeriesResponse(w, canonicalPaths, isJSONResponse)
@ -362,7 +362,7 @@ func TagsFindSeriesHandler(startTime time.Time, w http.ResponseWriter, r *http.R
paths = paths[:limit] paths = paths[:limit]
} }
w.Header().Set("Content-Type", "application/json; charset=utf-8") w.Header().Set("Content-Type", "application/json")
bw := bufferedwriter.Get(w) bw := bufferedwriter.Get(w)
defer bufferedwriter.Put(bw) defer bufferedwriter.Put(bw)
WriteTagsFindSeriesResponse(bw, paths) WriteTagsFindSeriesResponse(bw, paths)
@ -418,7 +418,7 @@ func TagValuesHandler(startTime time.Time, tagName string, w http.ResponseWriter
return err return err
} }
w.Header().Set("Content-Type", "application/json; charset=utf-8") w.Header().Set("Content-Type", "application/json")
bw := bufferedwriter.Get(w) bw := bufferedwriter.Get(w)
defer bufferedwriter.Put(bw) defer bufferedwriter.Put(bw)
WriteTagValuesResponse(bw, tagName, tagValues) WriteTagValuesResponse(bw, tagName, tagValues)
@ -449,7 +449,7 @@ func TagsHandler(startTime time.Time, w http.ResponseWriter, r *http.Request) er
return err return err
} }
w.Header().Set("Content-Type", "application/json; charset=utf-8") w.Header().Set("Content-Type", "application/json")
bw := bufferedwriter.Get(w) bw := bufferedwriter.Get(w)
defer bufferedwriter.Put(bw) defer bufferedwriter.Put(bw)
WriteTagsResponse(bw, labels) WriteTagsResponse(bw, labels)

View file

@ -200,7 +200,7 @@ func RequestHandler(w http.ResponseWriter, r *http.Request) bool {
} }
if strings.HasPrefix(path, "/functions") { if strings.HasPrefix(path, "/functions") {
graphiteFunctionsRequests.Inc() graphiteFunctionsRequests.Inc()
w.Header().Set("Content-Type", "application/json; charset=utf-8") w.Header().Set("Content-Type", "application/json")
fmt.Fprintf(w, "%s", `{}`) fmt.Fprintf(w, "%s", `{}`)
return true return true
} }
@ -404,25 +404,25 @@ func RequestHandler(w http.ResponseWriter, r *http.Request) bool {
case "/api/v1/rules", "/rules": case "/api/v1/rules", "/rules":
// Return dumb placeholder for https://prometheus.io/docs/prometheus/latest/querying/api/#rules // Return dumb placeholder for https://prometheus.io/docs/prometheus/latest/querying/api/#rules
rulesRequests.Inc() rulesRequests.Inc()
w.Header().Set("Content-Type", "application/json; charset=utf-8") w.Header().Set("Content-Type", "application/json")
fmt.Fprintf(w, "%s", `{"status":"success","data":{"groups":[]}}`) fmt.Fprintf(w, "%s", `{"status":"success","data":{"groups":[]}}`)
return true return true
case "/api/v1/alerts", "/alerts": case "/api/v1/alerts", "/alerts":
// Return dumb placeholder for https://prometheus.io/docs/prometheus/latest/querying/api/#alerts // Return dumb placeholder for https://prometheus.io/docs/prometheus/latest/querying/api/#alerts
alertsRequests.Inc() alertsRequests.Inc()
w.Header().Set("Content-Type", "application/json; charset=utf-8") w.Header().Set("Content-Type", "application/json")
fmt.Fprintf(w, "%s", `{"status":"success","data":{"alerts":[]}}`) fmt.Fprintf(w, "%s", `{"status":"success","data":{"alerts":[]}}`)
return true return true
case "/api/v1/metadata": case "/api/v1/metadata":
// Return dumb placeholder for https://prometheus.io/docs/prometheus/latest/querying/api/#querying-metric-metadata // Return dumb placeholder for https://prometheus.io/docs/prometheus/latest/querying/api/#querying-metric-metadata
metadataRequests.Inc() metadataRequests.Inc()
w.Header().Set("Content-Type", "application/json; charset=utf-8") w.Header().Set("Content-Type", "application/json")
fmt.Fprintf(w, "%s", `{"status":"success","data":{}}`) fmt.Fprintf(w, "%s", `{"status":"success","data":{}}`)
return true return true
case "/api/v1/query_exemplars": case "/api/v1/query_exemplars":
// Return dumb placeholder for https://prometheus.io/docs/prometheus/latest/querying/api/#querying-exemplars // Return dumb placeholder for https://prometheus.io/docs/prometheus/latest/querying/api/#querying-exemplars
queryExemplarsRequests.Inc() queryExemplarsRequests.Inc()
w.Header().Set("Content-Type", "application/json; charset=utf-8") w.Header().Set("Content-Type", "application/json")
fmt.Fprintf(w, "%s", `{"status":"success","data":null}`) fmt.Fprintf(w, "%s", `{"status":"success","data":null}`)
return true return true
case "/api/v1/admin/tsdb/delete_series": case "/api/v1/admin/tsdb/delete_series":
@ -459,7 +459,7 @@ func isGraphiteTagsPath(path string) bool {
func sendPrometheusError(w http.ResponseWriter, r *http.Request, err error) { func sendPrometheusError(w http.ResponseWriter, r *http.Request, err error) {
logger.Warnf("error in %q: %s", httpserver.GetRequestURI(r), err) logger.Warnf("error in %q: %s", httpserver.GetRequestURI(r), err)
w.Header().Set("Content-Type", "application/json; charset=utf-8") w.Header().Set("Content-Type", "application/json")
statusCode := http.StatusUnprocessableEntity statusCode := http.StatusUnprocessableEntity
var esc *httpserver.ErrorWithStatusCode var esc *httpserver.ErrorWithStatusCode
if errors.As(err, &esc) { if errors.As(err, &esc) {

View file

@ -533,7 +533,7 @@ func LabelValuesHandler(startTime time.Time, labelName string, w http.ResponseWr
} }
} }
w.Header().Set("Content-Type", "application/json; charset=utf-8") w.Header().Set("Content-Type", "application/json")
bw := bufferedwriter.Get(w) bw := bufferedwriter.Get(w)
defer bufferedwriter.Put(bw) defer bufferedwriter.Put(bw)
WriteLabelValuesResponse(bw, labelValues) WriteLabelValuesResponse(bw, labelValues)
@ -622,7 +622,7 @@ func LabelsCountHandler(startTime time.Time, w http.ResponseWriter, r *http.Requ
if err != nil { if err != nil {
return fmt.Errorf(`cannot obtain label entries: %w`, err) return fmt.Errorf(`cannot obtain label entries: %w`, err)
} }
w.Header().Set("Content-Type", "application/json; charset=utf-8") w.Header().Set("Content-Type", "application/json")
bw := bufferedwriter.Get(w) bw := bufferedwriter.Get(w)
defer bufferedwriter.Put(bw) defer bufferedwriter.Put(bw)
WriteLabelsCountResponse(bw, labelEntries) WriteLabelsCountResponse(bw, labelEntries)
@ -690,7 +690,7 @@ func TSDBStatusHandler(startTime time.Time, w http.ResponseWriter, r *http.Reque
return fmt.Errorf("cannot obtain tsdb status with matches for date=%d, topN=%d: %w", date, topN, err) return fmt.Errorf("cannot obtain tsdb status with matches for date=%d, topN=%d: %w", date, topN, err)
} }
} }
w.Header().Set("Content-Type", "application/json; charset=utf-8") w.Header().Set("Content-Type", "application/json")
bw := bufferedwriter.Get(w) bw := bufferedwriter.Get(w)
defer bufferedwriter.Put(bw) defer bufferedwriter.Put(bw)
WriteTSDBStatusResponse(bw, status) WriteTSDBStatusResponse(bw, status)
@ -784,7 +784,7 @@ func LabelsHandler(startTime time.Time, w http.ResponseWriter, r *http.Request)
} }
} }
w.Header().Set("Content-Type", "application/json; charset=utf-8") w.Header().Set("Content-Type", "application/json")
bw := bufferedwriter.Get(w) bw := bufferedwriter.Get(w)
defer bufferedwriter.Put(bw) defer bufferedwriter.Put(bw)
WriteLabelsResponse(bw, labels) WriteLabelsResponse(bw, labels)
@ -860,7 +860,7 @@ func SeriesCountHandler(startTime time.Time, w http.ResponseWriter, r *http.Requ
if err != nil { if err != nil {
return fmt.Errorf("cannot obtain series count: %w", err) return fmt.Errorf("cannot obtain series count: %w", err)
} }
w.Header().Set("Content-Type", "application/json; charset=utf-8") w.Header().Set("Content-Type", "application/json")
bw := bufferedwriter.Get(w) bw := bufferedwriter.Get(w)
defer bufferedwriter.Put(bw) defer bufferedwriter.Put(bw)
WriteSeriesCountResponse(bw, n) WriteSeriesCountResponse(bw, n)
@ -911,7 +911,7 @@ func SeriesHandler(startTime time.Time, w http.ResponseWriter, r *http.Request)
if err != nil { if err != nil {
return fmt.Errorf("cannot fetch time series for %q: %w", sq, err) return fmt.Errorf("cannot fetch time series for %q: %w", sq, err)
} }
w.Header().Set("Content-Type", "application/json; charset=utf-8") w.Header().Set("Content-Type", "application/json")
bw := bufferedwriter.Get(w) bw := bufferedwriter.Get(w)
defer bufferedwriter.Put(bw) defer bufferedwriter.Put(bw)
resultsCh := make(chan *quicktemplate.ByteBuffer) resultsCh := make(chan *quicktemplate.ByteBuffer)
@ -936,7 +936,7 @@ func SeriesHandler(startTime time.Time, w http.ResponseWriter, r *http.Request)
return fmt.Errorf("cannot fetch data for %q: %w", sq, err) return fmt.Errorf("cannot fetch data for %q: %w", sq, err)
} }
w.Header().Set("Content-Type", "application/json; charset=utf-8") w.Header().Set("Content-Type", "application/json")
bw := bufferedwriter.Get(w) bw := bufferedwriter.Get(w)
defer bufferedwriter.Put(bw) defer bufferedwriter.Put(bw)
resultsCh := make(chan *quicktemplate.ByteBuffer) resultsCh := make(chan *quicktemplate.ByteBuffer)
@ -1070,7 +1070,7 @@ func QueryHandler(startTime time.Time, w http.ResponseWriter, r *http.Request) e
} }
} }
w.Header().Set("Content-Type", "application/json; charset=utf-8") w.Header().Set("Content-Type", "application/json")
bw := bufferedwriter.Get(w) bw := bufferedwriter.Get(w)
defer bufferedwriter.Put(bw) defer bufferedwriter.Put(bw)
WriteQueryResponse(bw, result) WriteQueryResponse(bw, result)
@ -1163,7 +1163,7 @@ func queryRangeHandler(startTime time.Time, w http.ResponseWriter, query string,
// See https://github.com/VictoriaMetrics/VictoriaMetrics/issues/153 // See https://github.com/VictoriaMetrics/VictoriaMetrics/issues/153
result = removeEmptyValuesAndTimeseries(result) result = removeEmptyValuesAndTimeseries(result)
w.Header().Set("Content-Type", "application/json; charset=utf-8") w.Header().Set("Content-Type", "application/json")
bw := bufferedwriter.Get(w) bw := bufferedwriter.Get(w)
defer bufferedwriter.Put(bw) defer bufferedwriter.Put(bw)
WriteQueryRangeResponse(bw, result) WriteQueryRangeResponse(bw, result)
@ -1343,7 +1343,7 @@ func QueryStatsHandler(startTime time.Time, w http.ResponseWriter, r *http.Reque
return fmt.Errorf("cannot parse `maxLifetime` arg: %w", err) return fmt.Errorf("cannot parse `maxLifetime` arg: %w", err)
} }
maxLifetime := time.Duration(maxLifetimeMsecs) * time.Millisecond maxLifetime := time.Duration(maxLifetimeMsecs) * time.Millisecond
w.Header().Set("Content-Type", "application/json; charset=utf-8") w.Header().Set("Content-Type", "application/json")
bw := bufferedwriter.Get(w) bw := bufferedwriter.Get(w)
defer bufferedwriter.Put(bw) defer bufferedwriter.Put(bw)
querystats.WriteJSONQueryStats(bw, topN, maxLifetime) querystats.WriteJSONQueryStats(bw, topN, maxLifetime)

View file

@ -304,7 +304,7 @@ func RequestHandler(w http.ResponseWriter, r *http.Request) bool {
switch path { switch path {
case "/create": case "/create":
w.Header().Set("Content-Type", "application/json; charset=utf-8") w.Header().Set("Content-Type", "application/json")
snapshotPath, err := Storage.CreateSnapshot() snapshotPath, err := Storage.CreateSnapshot()
if err != nil { if err != nil {
err = fmt.Errorf("cannot create snapshot: %w", err) err = fmt.Errorf("cannot create snapshot: %w", err)
@ -318,7 +318,7 @@ func RequestHandler(w http.ResponseWriter, r *http.Request) bool {
} }
return true return true
case "/list": case "/list":
w.Header().Set("Content-Type", "application/json; charset=utf-8") w.Header().Set("Content-Type", "application/json")
snapshots, err := Storage.ListSnapshots() snapshots, err := Storage.ListSnapshots()
if err != nil { if err != nil {
err = fmt.Errorf("cannot list snapshots: %w", err) err = fmt.Errorf("cannot list snapshots: %w", err)
@ -335,7 +335,7 @@ func RequestHandler(w http.ResponseWriter, r *http.Request) bool {
fmt.Fprintf(w, `]}`) fmt.Fprintf(w, `]}`)
return true return true
case "/delete": case "/delete":
w.Header().Set("Content-Type", "application/json; charset=utf-8") w.Header().Set("Content-Type", "application/json")
snapshotName := r.FormValue("snapshot") snapshotName := r.FormValue("snapshot")
if err := Storage.DeleteSnapshot(snapshotName); err != nil { if err := Storage.DeleteSnapshot(snapshotName); err != nil {
err = fmt.Errorf("cannot delete snapshot %q: %w", snapshotName, err) err = fmt.Errorf("cannot delete snapshot %q: %w", snapshotName, err)
@ -345,7 +345,7 @@ func RequestHandler(w http.ResponseWriter, r *http.Request) bool {
fmt.Fprintf(w, `{"status":"ok"}`) fmt.Fprintf(w, `{"status":"ok"}`)
return true return true
case "/delete_all": case "/delete_all":
w.Header().Set("Content-Type", "application/json; charset=utf-8") w.Header().Set("Content-Type", "application/json")
snapshots, err := Storage.ListSnapshots() snapshots, err := Storage.ListSnapshots()
if err != nil { if err != nil {
err = fmt.Errorf("cannot list snapshots: %w", err) err = fmt.Errorf("cannot list snapshots: %w", err)

View file

@ -16,7 +16,7 @@ func WriteDatabaseNames(w http.ResponseWriter) {
// Emulate fake response for influx query. // Emulate fake response for influx query.
// This is required for TSBS benchmark and some Telegraf plugins. // This is required for TSBS benchmark and some Telegraf plugins.
// See https://github.com/VictoriaMetrics/VictoriaMetrics/issues/1124 // See https://github.com/VictoriaMetrics/VictoriaMetrics/issues/1124
w.Header().Set("Content-Type", "application/json; charset=utf-8") w.Header().Set("Content-Type", "application/json")
dbNames := *influxDatabaseNames dbNames := *influxDatabaseNames
if len(dbNames) == 0 { if len(dbNames) == 0 {
dbNames = []string{"_internal"} dbNames = []string{"_internal"}