Skip to content
This repository has been archived by the owner on Dec 17, 2024. It is now read-only.

Commit

Permalink
Sending correct Host header in drivers mode too
Browse files Browse the repository at this point in the history
  • Loading branch information
vania-pooh committed Jul 1, 2022
1 parent a974004 commit 8a0f80a
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 7 deletions.
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

0 comments on commit 8a0f80a

Please sign in to comment.