Skip to content

Commit eb6d800

Browse files
committed
Rely on Docker engine api v1.42 to return explicit content-types.
See https://docs.docker.com/reference/api/engine/version-history/#v142-api-changes
1 parent 538154e commit eb6d800

File tree

6 files changed

+12
-14
lines changed

6 files changed

+12
-14
lines changed

api-client/src/main/kotlin/de/gesellix/docker/remote/api/client/ContainerApi.kt

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -209,9 +209,8 @@ class ContainerApi(dockerClientConfig: DockerClientConfig = defaultClientConfig,
209209
) {
210210
val localVariableConfig = containerAttachRequestConfig(id = id, detachKeys = detachKeys, logs = logs, stream = stream, stdin = stdin, stdout = stdout, stderr = stderr)
211211

212-
val expectMultiplexedResponse = !(containerInspect(id, false).config?.tty ?: false)
213212
val localVarResponse = requestFrames(
214-
localVariableConfig, expectMultiplexedResponse
213+
localVariableConfig
215214
)
216215

217216
when (localVarResponse.responseType) {
@@ -851,9 +850,8 @@ class ContainerApi(dockerClientConfig: DockerClientConfig = defaultClientConfig,
851850
) {
852851
val localVariableConfig = containerLogsRequestConfig(id = id, follow = follow, stdout = stdout, stderr = stderr, since = since, until = until, timestamps = timestamps, tail = tail)
853852

854-
val expectMultiplexedResponse = !(containerInspect(id, false).config?.tty ?: false)
855853
val localVarResponse = requestFrames(
856-
localVariableConfig, expectMultiplexedResponse
854+
localVariableConfig
857855
)
858856

859857
when (localVarResponse.responseType) {

api-client/src/main/kotlin/de/gesellix/docker/remote/api/client/ExecApi.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ class ExecApi(dockerClientConfig: DockerClientConfig = defaultClientConfig, prox
245245
!(execInspect(id).processConfig?.tty ?: false)
246246
}
247247
val localVarResponse = requestFrames(
248-
localVariableConfig, expectMultiplexedResponse
248+
localVariableConfig
249249
)
250250

251251
val timeout = if (timeoutMillis == null) {

api-client/src/main/kotlin/de/gesellix/docker/remote/api/client/ServiceApi.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ class ServiceApi(dockerClientConfig: DockerClientConfig = defaultClientConfig, p
315315
val localVariableConfig = serviceLogsRequestConfig(id = id, details = details, follow = follow, stdout = stdout, stderr = stderr, since = since, timestamps = timestamps, tail = tail)
316316

317317
val localVarResponse = requestFrames(
318-
localVariableConfig, true /* do services/tasks always have container.tty == false? */
318+
localVariableConfig
319319
)
320320

321321
when (localVarResponse.responseType) {

api-client/src/main/kotlin/de/gesellix/docker/remote/api/client/TaskApi.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ class TaskApi(dockerClientConfig: DockerClientConfig = defaultClientConfig, prox
185185
val localVariableConfig = taskLogsRequestConfig(id = id, details = details, follow = follow, stdout = stdout, stderr = stderr, since = since, timestamps = timestamps, tail = tail)
186186

187187
val localVarResponse = requestFrames(
188-
localVariableConfig, true /* do services/tasks always have container.tty == false? */
188+
localVariableConfig
189189
)
190190

191191
when (localVarResponse.responseType) {

api-client/src/main/kotlin/de/gesellix/docker/remote/api/core/ApiClient.kt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -143,15 +143,15 @@ open class ApiClient(
143143
return requestStream(request, client)
144144
}
145145

146-
protected fun requestFrames(requestConfig: RequestConfig, expectMultiplexedResponse: Boolean = false): ApiInfrastructureResponse<Frame> {
146+
protected fun requestFrames(requestConfig: RequestConfig): ApiInfrastructureResponse<Frame> {
147147
val engineRequest = EngineRequest(requestConfig.method, requestConfig.path).also {
148148
it.headers = requestConfig.headers
149149
it.query = requestConfig.query
150150
it.body = requestConfig.body
151151
}
152-
val request = prepareRequest(engineRequest, DockerRawStreamMediaType)
152+
val request = prepareRequest(engineRequest)
153153
val client = prepareClient(engineRequest)
154-
return requestFrames(request, client, expectMultiplexedResponse)
154+
return requestFrames(request, client)
155155
}
156156

157157
protected fun prepareRequest(requestConfig: EngineRequest, fallbackContentType: String = ""): Request {
@@ -309,7 +309,7 @@ open class ApiClient(
309309
}
310310
}
311311

312-
protected fun requestFrames(request: Request, client: OkHttpClient, expectMultiplexedResponse: Boolean = false): ApiInfrastructureResponse<Frame> {
312+
protected fun requestFrames(request: Request, client: OkHttpClient): ApiInfrastructureResponse<Frame> {
313313
val response = client.newCall(request).execute()
314314
val mediaType = response.header(ContentType)?.substringBefore(";")?.lowercase(Locale.getDefault())
315315

@@ -325,7 +325,7 @@ open class ApiClient(
325325
response.headers.toMultimap()
326326
)
327327
response.isSuccessful -> return SuccessStream(
328-
response.body.consumeFrames(mediaType, expectMultiplexedResponse),
328+
response.body.consumeFrames(mediaType),
329329
response.code,
330330
response.headers.toMultimap()
331331
)

api-client/src/main/kotlin/de/gesellix/docker/remote/api/core/ResponseConsumer.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ inline fun <reified T : Any?> ResponseBody?.consumeStream(mediaType: String?): F
5757
}
5858
}
5959

60-
fun ResponseBody?.consumeFrames(mediaType: String?, expectMultiplexedResponse: Boolean = false): Flow<Frame> {
60+
fun ResponseBody?.consumeFrames(mediaType: String?): Flow<Frame> {
6161
if (this == null) {
6262
return emptyFlow()
6363
}
@@ -66,7 +66,7 @@ fun ResponseBody?.consumeFrames(mediaType: String?, expectMultiplexedResponse: B
6666
ApiClient.Companion.DockerMultiplexedStreamMediaType,
6767
// raw-stream: with attached Tty
6868
ApiClient.Companion.DockerRawStreamMediaType -> {
69-
val reader = FrameReader(source(), expectMultiplexedResponse)
69+
val reader = FrameReader(source(), mediaType == ApiClient.Companion.DockerMultiplexedStreamMediaType)
7070
val events = flow {
7171
while (reader.hasNext()) {
7272
val next = reader.readNext(Frame::class.java)

0 commit comments

Comments
 (0)