2024-04-02 14:51:18 +00:00
|
|
|
package firehose
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"net/http"
|
|
|
|
"time"
|
2024-07-17 11:52:10 +00:00
|
|
|
|
|
|
|
"github.com/VictoriaMetrics/VictoriaMetrics/lib/stringsutil"
|
2024-04-02 14:51:18 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// WriteSuccessResponse writes success response for AWS Firehose request.
|
|
|
|
//
|
|
|
|
// See https://docs.aws.amazon.com/firehose/latest/dev/httpdeliveryrequestresponse.html#responseformat
|
|
|
|
func WriteSuccessResponse(w http.ResponseWriter, r *http.Request) {
|
|
|
|
requestID := r.Header.Get("X-Amz-Firehose-Request-Id")
|
|
|
|
if requestID == "" {
|
2024-07-16 07:43:47 +00:00
|
|
|
// This isn't a AWS firehose request - just return an empty response in this case.
|
2024-04-02 14:51:18 +00:00
|
|
|
w.WriteHeader(http.StatusOK)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2024-07-17 11:52:10 +00:00
|
|
|
body := fmt.Sprintf(`{"requestId":%s,"timestamp":%d}`, stringsutil.JSONString(requestID), time.Now().UnixMilli())
|
2024-04-02 14:51:18 +00:00
|
|
|
|
|
|
|
h := w.Header()
|
|
|
|
h.Set("Content-Type", "application/json")
|
|
|
|
h.Set("Content-Length", fmt.Sprintf("%d", len(body)))
|
|
|
|
w.Write([]byte(body))
|
|
|
|
}
|