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

Sending correct Host header in drivers mode too #1244

Merged
merged 1 commit into from
Jul 1, 2022
Merged
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
9 changes: 5 additions & 4 deletions selenoid.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,8 +201,8 @@ func create(w http.ResponseWriter, r *http.Request) {
u := startedService.Url
cancel := startedService.Cancel
host := "localhost"
if startedService.Container != nil {
host = startedService.Container.Origin
if startedService.Origin != "" {
host = startedService.Origin
}

var resp *http.Response
Expand Down Expand Up @@ -300,6 +300,7 @@ func create(w http.ResponseWriter, r *http.Request) {
URL: u,
Container: startedService.Container,
HostPort: startedService.HostPort,
Origin: startedService.Origin,
Timeout: sessionTimeout,
TimeoutCh: onTimeout(sessionTimeout, func() {
request{r}.session(s.ID).Delete(requestId)
Expand Down Expand Up @@ -532,8 +533,8 @@ func proxy(w http.ResponseWriter, r *http.Request) {
}
r.URL.Host, r.URL.Path = sess.URL.Host, path.Clean(sess.URL.Path+r.URL.Path)
r.Host = "localhost"
if sess.Container != nil {
r.Host = sess.Container.Origin
if sess.Origin != "" {
r.Host = sess.Origin
}
return
}
Expand Down
2 changes: 1 addition & 1 deletion service/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -231,10 +231,10 @@ func (d *Docker) StartWithCancel() (*StartedService, error) {
Container: &session.Container{
ID: browserContainerId,
IPAddress: getContainerIP(d.Environment.Network, stat),
Origin: origin,
Ports: publishedPortsInfo,
},
HostPort: hostPort,
Origin: origin,
Cancel: func() {
if videoContainerId != "" {
stopVideoContainer(ctx, cl, requestId, videoContainerId, d.Environment)
Expand Down
2 changes: 1 addition & 1 deletion service/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ func (d *Driver) StartWithCancel() (*StartedService, error) {
if d.Caps.VNC {
hp.VNC = "127.0.0.1:5900"
}
return &StartedService{Url: u, HostPort: hp, Cancel: func() { d.stopProcess(cmd) }}, nil
return &StartedService{Url: u, HostPort: hp, Origin: fmt.Sprintf("localhost:%s", port), Cancel: func() { d.stopProcess(cmd) }}, nil
}

func (d *Driver) stopProcess(cmd *exec.Cmd) {
Expand Down
1 change: 1 addition & 0 deletions service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ type StartedService struct {
Url *url.URL
Container *session.Container
HostPort session.HostPort
Origin string
Cancel func()
}

Expand Down
2 changes: 1 addition & 1 deletion session/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ func (c *Caps) BrowserName() string {
type Container struct {
ID string `json:"id"`
IPAddress string `json:"ip"`
Origin string `json:"origin,omitempty"`
Ports map[string]string `json:"exposedPorts,omitempty"`
}

Expand All @@ -76,6 +75,7 @@ type Session struct {
URL *url.URL
Container *Container
HostPort HostPort
Origin string
Cancel func()
Timeout time.Duration
TimeoutCh chan struct{}
Expand Down