From 4e0c08e9c5b028d41a3c0bf832b3dcdacb1f9988 Mon Sep 17 00:00:00 2001 From: Harshavardhana Date: Mon, 3 Jul 2017 19:59:41 -0700 Subject: [PATCH] ListenBucketNotification should set proper MIME type. (#4621) This is needed to avoid proxies buffering the connection this is also a HTTP standard way to handle this situation where server is sending back events in asynchronously. For more details read https://goo.gl/RCML9f Fixes - https://github.com/minio/minio-go/issues/731 --- cmd/bucket-notification-handlers.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/cmd/bucket-notification-handlers.go b/cmd/bucket-notification-handlers.go index afbe4f684..efc598f6f 100644 --- a/cmd/bucket-notification-handlers.go +++ b/cmd/bucket-notification-handlers.go @@ -204,6 +204,15 @@ func writeNotification(w http.ResponseWriter, notification map[string][]Notifica if err != nil { return err } + + // https://github.com/containous/traefik/issues/560 + // https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events/Using_server-sent_events + // + // Proxies might buffer the connection to avoid this we + // need the proper MIME type before writing to client. + // This MIME header tells the proxies to avoid buffering + w.Header().Set("Content-Type", "text/event-stream") + // Add additional CRLF characters for client to // differentiate the individual events properly. _, err = w.Write(append(notificationBytes, crlf...))