Read only http header and give rest to vnc client
This commit is contained in:
parent
6005f12d3d
commit
e8feeffb3f
@ -105,19 +105,46 @@ func (self *StepTypeBootCommand) Run(ctx context.Context, state multistep.StateB
|
|||||||
return multistep.ActionHalt
|
return multistep.ActionHalt
|
||||||
}
|
}
|
||||||
|
|
||||||
buffer := make([]byte, 10000)
|
// Look for \r\n\r\n sequence. Everything after the HTTP Header is for the vnc client.
|
||||||
_, err = tlsConn.Read(buffer)
|
|
||||||
if err != nil && err != io.EOF {
|
builder := strings.Builder{}
|
||||||
err := fmt.Errorf("failed to read vnc session response: %v", err)
|
buffer := make([]byte, 1)
|
||||||
state.Put("error", err)
|
sequenceProgress := 0
|
||||||
ui.Error(err.Error())
|
|
||||||
return multistep.ActionHalt
|
for {
|
||||||
|
if _, err := io.ReadFull(tlsConn, buffer); err != nil {
|
||||||
|
err := fmt.Errorf("failed to start vnc session: %v", err)
|
||||||
|
state.Put("error", err)
|
||||||
|
ui.Error(err.Error())
|
||||||
|
return multistep.ActionHalt
|
||||||
|
}
|
||||||
|
|
||||||
|
builder.WriteByte(buffer[0])
|
||||||
|
|
||||||
|
if buffer[0] == '\n' && sequenceProgress % 2 == 1 {
|
||||||
|
sequenceProgress++
|
||||||
|
} else if buffer[0] == '\r' && sequenceProgress % 2 == 0 {
|
||||||
|
sequenceProgress++
|
||||||
|
} else {
|
||||||
|
sequenceProgress = 0
|
||||||
|
}
|
||||||
|
|
||||||
|
if sequenceProgress == 4 {
|
||||||
|
break
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ui.Say(fmt.Sprintf("Received response: %s", string(buffer)))
|
ui.Say(fmt.Sprintf("Received response: %s", builder.String()))
|
||||||
|
|
||||||
|
// Make sure the VNC Handshake times out when it can't read anything.
|
||||||
|
duration,_ := time.ParseDuration("30s")
|
||||||
|
tlsConn.SetDeadline(time.Now().Add(duration))
|
||||||
vncClient, err := vnc.Client(tlsConn, &vnc.ClientConfig{Exclusive: true})
|
vncClient, err := vnc.Client(tlsConn, &vnc.ClientConfig{Exclusive: true})
|
||||||
|
|
||||||
|
// Make sure further requests don't time out.
|
||||||
|
duration,_ = time.ParseDuration("1d")
|
||||||
|
tlsConn.SetDeadline(time.Now().Add(duration))
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err := fmt.Errorf("Error establishing VNC session: %s", err)
|
err := fmt.Errorf("Error establishing VNC session: %s", err)
|
||||||
state.Put("error", err)
|
state.Put("error", err)
|
||||||
|
Loading…
Reference in New Issue
Block a user