Skip to content
This repository was archived by the owner on Nov 13, 2025. It is now read-only.
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
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import okhttp3.Interceptor;
import okhttp3.Request;
import okhttp3.Response;
import okhttp3.internal.connection.RealConnection;
import okio.Buffer;
import okio.BufferedSink;
import okio.Okio;
Expand Down Expand Up @@ -51,14 +52,15 @@ public Response intercept(Interceptor.Chain chain) throws IOException {
.build();
}

// chain.connection().socket().setSoTimeout(0);
Response response = chain.proceed(modifiedRequest);

if (!(response.code() == 101 || response.isSuccessful()) || stdin == null) {
return response;
}
// TcpUpgradeVerificator.ensureTcpUpgrade(response);

connection.socket().setSoTimeout(0);
((RealConnection) connection).setNoNewExchanges(true);
chain.call().timeout().clearTimeout().clearDeadline();

// stdin -> sink
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import okio.Okio
import spock.lang.IgnoreIf
import spock.lang.Requires
import spock.lang.Specification
import spock.lang.Unroll

import java.util.concurrent.CountDownLatch

Expand Down Expand Up @@ -109,19 +110,18 @@ class OkDockerClientIntegrationSpec extends Specification {
response.status.code == 200
}

def "attach (interactive)"() {
@Unroll
def "attach (openStdin: #openStdin, tty: #tty)"() {
given:
def client = new OkDockerClient()

// pull image (ensure it exists locally)
client.post([path : "/images/create",
query: [fromImage: CONSTANTS.imageName]])
// create container
// docker run --rm -it gesellix/testimage:os-windows cmd /V:ON /C "set /p line= & echo #!line!#"
def containerConfig = [
Tty : true,
// Tty : false,
OpenStdin : true,
Tty : tty,
OpenStdin : openStdin,
Image : CONSTANTS.imageName,
Entrypoint: ["/cat"]
]
Expand Down Expand Up @@ -150,6 +150,7 @@ class OkDockerClientIntegrationSpec extends Specification {

def attachConfig = new AttachConfig(!containerConfig.Tty)
attachConfig.streams.stdin = new PipedInputStream(stdin)
// attachConfig.streams.stdout = stdout
attachConfig.streams.stdout = new TeeOutputStream(stdout, System.out)
attachConfig.onResponse = { Response response ->
log.info("[attach (interactive)] got response")
Expand All @@ -171,6 +172,7 @@ class OkDockerClientIntegrationSpec extends Specification {
log.info("[attach (interactive)] consumed (complete: ${stdout.toString() == expectedOutput})\n${stdout.toString()}")
}
}
// new OkDockerClient().post([
client.post([
path : "/containers/${containerId}/attach".toString(),
query : [logs: true, stream: true, stdin: true, stdout: true, stderr: true],
Expand All @@ -195,5 +197,10 @@ class OkDockerClientIntegrationSpec extends Specification {
client.post([path: "/containers/${containerId}/stop".toString(), query: [t: 10]])
client.post([path: "/containers/${containerId}/wait".toString()])
client.delete([path: "/containers/${containerId}".toString(), query: [:]])

where:
tty | openStdin
false | true
// true | true // TODO: fix on Windows
}
}