From 787aea5f3182f1c04f04427b39de79aaa641c58e Mon Sep 17 00:00:00 2001 From: Hector Sanjuan Date: Mon, 4 Apr 2022 12:09:54 +0200 Subject: [PATCH] Always include the X-Stream-Error trailer (even without errors) This is to potentially address things like this: https://github.com/nodejs/undici/issues/432#issuecomment-1047931107 --- api/common/api.go | 4 ++++ api/rest/client/request.go | 4 +++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/api/common/api.go b/api/common/api.go index 094c439c..24c06096 100644 --- a/api/common/api.go +++ b/api/common/api.go @@ -644,6 +644,10 @@ func (api *API) StreamResponse(w http.ResponseWriter, next StreamIterator, errCh if err != nil { w.Header().Set("X-Stream-Error", err.Error()) + } else { + // Due to some Javascript-browser-land stuff, we set the header + // even when there is no error. + w.Header().Set("X-Stream-Error", "") } // check for function errors for funcErr := range errCh { diff --git a/api/rest/client/request.go b/api/rest/client/request.go index 0d80f888..98aaa943 100644 --- a/api/rest/client/request.go +++ b/api/rest/client/request.go @@ -156,7 +156,9 @@ func (c *defaultClient) handleStreamResponse(resp *http.Response, handler respon trailerErrs := resp.Trailer.Values("X-Stream-Error") var err error for _, trailerErr := range trailerErrs { - err = multierr.Append(err, errors.New(trailerErr)) + if trailerErr != "" { + err = multierr.Append(err, errors.New(trailerErr)) + } } if err != nil {