Skip to content
This repository has been archived by the owner on Aug 3, 2023. It is now read-only.

Commit

Permalink
Copy response headers through proxied requests
Browse files Browse the repository at this point in the history
Signed-off-by: Francesco Torchia <francesco.torchia@suse.com>
  • Loading branch information
torchiaf committed Jul 3, 2023
1 parent f7e7367 commit 6fd3f59
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 18 deletions.
5 changes: 5 additions & 0 deletions src/jetstream/passthrough.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Expand Down Expand Up @@ -593,6 +594,10 @@ func (p *portalProxy) ProxySingleRequest(c echo.Context) error {
go p.doRequest(&cnsiRequest, done)
res := <-done

for header := range res.ResponseHeader {
c.Response().Header().Set(header, res.ResponseHeader.Get(header))
}

// FIXME: cnsiRequest.Status info is lost for failures, only get a status code
c.Response().WriteHeader(res.StatusCode)

Expand Down
37 changes: 19 additions & 18 deletions src/jetstream/repository/interfaces/structs.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down Expand Up @@ -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 (
Expand All @@ -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,
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 6fd3f59

Please sign in to comment.