From 5773f299a9462eefec89dbbcd1f95a114596d2cf Mon Sep 17 00:00:00 2001 From: Francesco Torchia Date: Fri, 4 Aug 2023 12:09:48 +0200 Subject: [PATCH] backend, Copy response headers through proxied requests Signed-off-by: Francesco Torchia --- backend/src/jetstream/passthrough.go | 4 ++ .../repository/interfaces/structs.go | 37 ++++++++++--------- 2 files changed, 23 insertions(+), 18 deletions(-) diff --git a/backend/src/jetstream/passthrough.go b/backend/src/jetstream/passthrough.go index 905164a..9d2b034 100644 --- a/backend/src/jetstream/passthrough.go +++ b/backend/src/jetstream/passthrough.go @@ -525,6 +525,7 @@ func (p *portalProxy) doRequest(cnsiRequest *interfaces.CNSIRequest, done chan<- } else if res.Body != nil { cnsiRequest.StatusCode = res.StatusCode cnsiRequest.Status = res.Status + cnsiRequest.ResponseHeader = res.Header cnsiRequest.Response, cnsiRequest.Error = ioutil.ReadAll(res.Body) defer res.Body.Close() } @@ -593,6 +594,9 @@ func (p *portalProxy) ProxySingleRequest(c echo.Context) error { go p.doRequest(&cnsiRequest, done) res := <-done + // Copy content-length header from original response header + c.Response().Header().Set("proxy-content-length", res.ResponseHeader.Get("content-length")) + // FIXME: cnsiRequest.Status info is lost for failures, only get a status code c.Response().WriteHeader(res.StatusCode) diff --git a/backend/src/jetstream/repository/interfaces/structs.go b/backend/src/jetstream/repository/interfaces/structs.go index fe4eb4a..9bb7f73 100644 --- a/backend/src/jetstream/repository/interfaces/structs.go +++ b/backend/src/jetstream/repository/interfaces/structs.go @@ -39,7 +39,7 @@ type V2Info struct { type InfoFunc func(apiEndpoint string, skipSSLValidation bool) (CNSIRecord, interface{}, error) -//TODO this could be moved back to cnsis subpackage, and extensions could import it? +// TODO this could be moved back to cnsis subpackage, and extensions could import it? type CNSIRecord struct { GUID string `json:"guid"` Name string `json:"name"` @@ -260,7 +260,7 @@ type Versions struct { DatabaseVersion int64 `json:"database_version"` } -//AuthEndpointType - Restrict the possible values of the configured +// AuthEndpointType - Restrict the possible values of the configured type AuthEndpointType string const ( @@ -274,8 +274,8 @@ const ( AuthNone AuthEndpointType = "none" ) -//AuthEndpointTypes - Allows lookup of internal string representation by the -//value of the AUTH_ENDPOINT_TYPE env variable +// AuthEndpointTypes - Allows lookup of internal string representation by the +// value of the AUTH_ENDPOINT_TYPE env variable var AuthEndpointTypes = map[string]AuthEndpointType{ "remote": Remote, "local": Local, @@ -352,20 +352,21 @@ func (consoleConfig *ConsoleConfig) IsSetupComplete() bool { // CNSIRequest type CNSIRequest struct { - GUID string `json:"-"` - UserGUID string `json:"-"` - Method string `json:"-"` - Body []byte `json:"-"` - Header http.Header `json:"-"` - URL *url.URL `json:"-"` - StatusCode int `json:"statusCode"` - Status string `json:"status"` - PassThrough bool `json:"-"` - LongRunning bool `json:"-"` - Response []byte `json:"-"` - Error error `json:"-"` - ResponseGUID string `json:"-"` - Token *TokenRecord `json:"-"` // Optional Token record to use instead of looking up + GUID string `json:"-"` + UserGUID string `json:"-"` + Method string `json:"-"` + Body []byte `json:"-"` + Header http.Header `json:"-"` + URL *url.URL `json:"-"` + StatusCode int `json:"statusCode"` + Status string `json:"status"` + PassThrough bool `json:"-"` + LongRunning bool `json:"-"` + ResponseHeader http.Header `json:"-"` + Response []byte `json:"-"` + Error error `json:"-"` + ResponseGUID string `json:"-"` + Token *TokenRecord `json:"-"` // Optional Token record to use instead of looking up } type PortalConfig struct {