added support for upload and download functions of the gommand interactive agent through the proxy
This commit is contained in:
parent
2b0f897f18
commit
495f26caed
|
@ -396,7 +396,9 @@ func (app *App) proxyAgentHandler(w http.ResponseWriter, r *http.Request) {
|
|||
ForceAttemptHTTP2: false,
|
||||
},
|
||||
FlushInterval: -1,
|
||||
|
||||
ModifyResponse: func(resp *http.Response) error {
|
||||
// Patch the base tag for seemless translation of the proxy
|
||||
if strings.HasPrefix(resp.Header.Get("Content-Type"), "text/html") {
|
||||
body, _ := io.ReadAll(resp.Body)
|
||||
patched := bytes.Replace(
|
||||
|
@ -408,6 +410,20 @@ func (app *App) proxyAgentHandler(w http.ResponseWriter, r *http.Request) {
|
|||
resp.ContentLength = int64(len(patched))
|
||||
resp.Header.Set("Content-Length", strconv.Itoa(len(patched)))
|
||||
}
|
||||
|
||||
// patch relative redirects coming from the agent
|
||||
// e.g. download function of the interactive agent
|
||||
if loc := resp.Header.Get("Location"); loc != "" {
|
||||
if !strings.HasPrefix(loc, "http://") &&
|
||||
!strings.HasPrefix(loc, "https://") &&
|
||||
!strings.HasPrefix(loc, "/proxyAgent/") {
|
||||
// Remove leading "/" if present, prefix with the tunnel
|
||||
loc = strings.TrimPrefix(loc, "/")
|
||||
fixed := fmt.Sprintf("/proxyAgent/%s/%s", agentKey, loc)
|
||||
resp.Header.Set("Location", fixed)
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
},
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue