Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Copy response headers through proxied requests #294

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions backend/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,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)

Expand Down
37 changes: 19 additions & 18 deletions backend/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
Loading