@@ -25,7 +25,7 @@ internal ContainerOperations(DockerClient client)
2525 _client = client ;
2626 }
2727
28- public async Task < IList < ContainerListResponse > > ListContainersAsync ( ContainersListParameters parameters , CancellationToken cancellationToken = default ( CancellationToken ) )
28+ public async Task < IList < ContainerListResponse > > ListContainersAsync ( ContainersListParameters parameters , CancellationToken cancellationToken = default )
2929 {
3030 if ( parameters == null )
3131 {
@@ -36,7 +36,7 @@ internal ContainerOperations(DockerClient client)
3636 return await _client . MakeRequestAsync < ContainerListResponse [ ] > ( _client . NoErrorHandlers , HttpMethod . Get , "containers/json" , queryParameters , cancellationToken ) . ConfigureAwait ( false ) ;
3737 }
3838
39- public async Task < CreateContainerResponse > CreateContainerAsync ( CreateContainerParameters parameters , CancellationToken cancellationToken = default ( CancellationToken ) )
39+ public async Task < CreateContainerResponse > CreateContainerAsync ( CreateContainerParameters parameters , CancellationToken cancellationToken = default )
4040 {
4141 IQueryString qs = null ;
4242
@@ -54,7 +54,7 @@ internal ContainerOperations(DockerClient client)
5454 return await _client . MakeRequestAsync < CreateContainerResponse > ( new [ ] { NoSuchImageHandler } , HttpMethod . Post , "containers/create" , qs , data , cancellationToken ) . ConfigureAwait ( false ) ;
5555 }
5656
57- public async Task < ContainerInspectResponse > InspectContainerAsync ( string id , CancellationToken cancellationToken = default ( CancellationToken ) )
57+ public async Task < ContainerInspectResponse > InspectContainerAsync ( string id , CancellationToken cancellationToken = default )
5858 {
5959 if ( string . IsNullOrEmpty ( id ) )
6060 {
@@ -64,7 +64,7 @@ internal ContainerOperations(DockerClient client)
6464 return await _client . MakeRequestAsync < ContainerInspectResponse > ( new [ ] { NoSuchContainerHandler } , HttpMethod . Get , $ "containers/{ id } /json", cancellationToken ) . ConfigureAwait ( false ) ;
6565 }
6666
67- public async Task < ContainerInspectResponse > InspectContainerAsync ( string id , ContainerInspectParameters parameters , CancellationToken cancellationToken = default ( CancellationToken ) )
67+ public async Task < ContainerInspectResponse > InspectContainerAsync ( string id , ContainerInspectParameters parameters , CancellationToken cancellationToken = default )
6868 {
6969 if ( string . IsNullOrEmpty ( id ) )
7070 {
@@ -80,7 +80,7 @@ internal ContainerOperations(DockerClient client)
8080 return await _client . MakeRequestAsync < ContainerInspectResponse > ( new [ ] { NoSuchContainerHandler } , HttpMethod . Get , $ "containers/{ id } /json", queryString , cancellationToken ) . ConfigureAwait ( false ) ;
8181 }
8282
83- public async Task < ContainerProcessesResponse > ListProcessesAsync ( string id , ContainerListProcessesParameters parameters , CancellationToken cancellationToken = default ( CancellationToken ) )
83+ public async Task < ContainerProcessesResponse > ListProcessesAsync ( string id , ContainerListProcessesParameters parameters , CancellationToken cancellationToken = default )
8484 {
8585 if ( string . IsNullOrEmpty ( id ) )
8686 {
@@ -96,32 +96,16 @@ internal ContainerOperations(DockerClient client)
9696 return await _client . MakeRequestAsync < ContainerProcessesResponse > ( new [ ] { NoSuchContainerHandler } , HttpMethod . Get , $ "containers/{ id } /top", queryParameters , cancellationToken ) . ConfigureAwait ( false ) ;
9797 }
9898
99- public Task < Stream > GetContainerLogsAsync ( string id , ContainerLogsParameters parameters , CancellationToken cancellationToken = default ( CancellationToken ) )
99+ public async Task GetContainerLogsAsync ( string id , ContainerLogsParameters parameters , IProgress < string > progress , CancellationToken cancellationToken = default )
100100 {
101- if ( string . IsNullOrEmpty ( id ) )
102- {
103- throw new ArgumentNullException ( nameof ( id ) ) ;
104- }
105-
106- if ( parameters == null )
107- {
108- throw new ArgumentNullException ( nameof ( parameters ) ) ;
109- }
101+ using var multiplexedStream = await GetContainerLogsAsync ( id , parameters , cancellationToken )
102+ . ConfigureAwait ( false ) ;
110103
111- IQueryString queryParameters = new QueryString < ContainerLogsParameters > ( parameters ) ;
112- return _client . MakeRequestForStreamAsync ( new [ ] { NoSuchContainerHandler } , HttpMethod . Get , $ "containers/ { id } /logs" , queryParameters , cancellationToken ) ;
104+ await StreamUtil . MonitorStreamAsync ( multiplexedStream , progress , cancellationToken )
105+ . ConfigureAwait ( false ) ;
113106 }
114107
115- public Task GetContainerLogsAsync ( string id , ContainerLogsParameters parameters , CancellationToken cancellationToken , IProgress < string > progress )
116- {
117- return StreamUtil . MonitorStreamAsync (
118- GetContainerLogsAsync ( id , parameters , cancellationToken ) ,
119- _client ,
120- cancellationToken ,
121- progress ) ;
122- }
123-
124- public async Task < MultiplexedStream > GetContainerLogsAsync ( string id , bool tty , ContainerLogsParameters parameters , CancellationToken cancellationToken = default ( CancellationToken ) )
108+ public async Task < MultiplexedStream > GetContainerLogsAsync ( string id , ContainerLogsParameters parameters , CancellationToken cancellationToken = default )
125109 {
126110 if ( string . IsNullOrEmpty ( id ) )
127111 {
@@ -133,14 +117,18 @@ public Task GetContainerLogsAsync(string id, ContainerLogsParameters parameters,
133117 throw new ArgumentNullException ( nameof ( parameters ) ) ;
134118 }
135119
136- IQueryString queryParameters = new QueryString < ContainerLogsParameters > ( parameters ) ;
120+ var queryParameters = new QueryString < ContainerLogsParameters > ( parameters ) ;
137121
138- Stream result = await _client . MakeRequestForStreamAsync ( new [ ] { NoSuchContainerHandler } , HttpMethod . Get , $ "containers/{ id } /logs", queryParameters , cancellationToken ) . ConfigureAwait ( false ) ;
122+ var containerInspectResponse = await InspectContainerAsync ( id , cancellationToken )
123+ . ConfigureAwait ( false ) ;
139124
140- return new MultiplexedStream ( result , ! tty ) ;
125+ var stream = await _client . MakeRequestForStreamAsync ( new [ ] { NoSuchContainerHandler } , HttpMethod . Get , $ "containers/{ id } /logs", queryParameters , null , null , cancellationToken )
126+ . ConfigureAwait ( false ) ;
127+
128+ return new MultiplexedStream ( stream , ! containerInspectResponse . Config . Tty ) ;
141129 }
142130
143- public async Task < IList < ContainerFileSystemChangeResponse > > InspectChangesAsync ( string id , CancellationToken cancellationToken = default ( CancellationToken ) )
131+ public async Task < IList < ContainerFileSystemChangeResponse > > InspectChangesAsync ( string id , CancellationToken cancellationToken = default )
144132 {
145133 if ( string . IsNullOrEmpty ( id ) )
146134 {
@@ -176,7 +164,7 @@ public Task<Stream> GetContainerStatsAsync(string id, ContainerStatsParameters p
176164 return _client . MakeRequestForStreamAsync ( new [ ] { NoSuchContainerHandler } , HttpMethod . Get , $ "containers/{ id } /stats", queryParameters , null , null , cancellationToken ) ;
177165 }
178166
179- public Task GetContainerStatsAsync ( string id , ContainerStatsParameters parameters , IProgress < ContainerStatsResponse > progress , CancellationToken cancellationToken = default ( CancellationToken ) )
167+ public Task GetContainerStatsAsync ( string id , ContainerStatsParameters parameters , IProgress < ContainerStatsResponse > progress , CancellationToken cancellationToken = default )
180168 {
181169 return StreamUtil . MonitorStreamForMessagesAsync (
182170 GetContainerStatsAsync ( id , parameters , cancellationToken ) ,
@@ -185,7 +173,7 @@ public Task<Stream> GetContainerStatsAsync(string id, ContainerStatsParameters p
185173 progress ) ;
186174 }
187175
188- public Task ResizeContainerTtyAsync ( string id , ContainerResizeParameters parameters , CancellationToken cancellationToken = default ( CancellationToken ) )
176+ public Task ResizeContainerTtyAsync ( string id , ContainerResizeParameters parameters , CancellationToken cancellationToken = default )
189177 {
190178 if ( string . IsNullOrEmpty ( id ) )
191179 {
@@ -201,7 +189,7 @@ public Task<Stream> GetContainerStatsAsync(string id, ContainerStatsParameters p
201189 return _client . MakeRequestAsync ( new [ ] { NoSuchContainerHandler } , HttpMethod . Post , $ "containers/{ id } /resize", queryParameters , cancellationToken ) ;
202190 }
203191
204- public async Task < bool > StartContainerAsync ( string id , ContainerStartParameters parameters , CancellationToken cancellationToken = default ( CancellationToken ) )
192+ public async Task < bool > StartContainerAsync ( string id , ContainerStartParameters parameters , CancellationToken cancellationToken = default )
205193 {
206194 if ( string . IsNullOrEmpty ( id ) )
207195 {
@@ -214,7 +202,7 @@ public Task<Stream> GetContainerStatsAsync(string id, ContainerStatsParameters p
214202 return result ?? throw new InvalidOperationException ( ) ;
215203 }
216204
217- public async Task < bool > StopContainerAsync ( string id , ContainerStopParameters parameters , CancellationToken cancellationToken = default ( CancellationToken ) )
205+ public async Task < bool > StopContainerAsync ( string id , ContainerStopParameters parameters , CancellationToken cancellationToken = default )
218206 {
219207 if ( string . IsNullOrEmpty ( id ) )
220208 {
@@ -234,7 +222,7 @@ public Task<Stream> GetContainerStatsAsync(string id, ContainerStatsParameters p
234222 return result ?? throw new InvalidOperationException ( ) ;
235223 }
236224
237- public Task RestartContainerAsync ( string id , ContainerRestartParameters parameters , CancellationToken cancellationToken = default ( CancellationToken ) )
225+ public Task RestartContainerAsync ( string id , ContainerRestartParameters parameters , CancellationToken cancellationToken = default )
238226 {
239227 if ( string . IsNullOrEmpty ( id ) )
240228 {
@@ -253,7 +241,7 @@ public Task<Stream> GetContainerStatsAsync(string id, ContainerStatsParameters p
253241 return _client . MakeRequestAsync ( new [ ] { NoSuchContainerHandler } , HttpMethod . Post , $ "containers/{ id } /restart", queryParameters , null , null , TimeSpan . FromMilliseconds ( Timeout . Infinite ) , cancellationToken ) ;
254242 }
255243
256- public Task KillContainerAsync ( string id , ContainerKillParameters parameters , CancellationToken cancellationToken = default ( CancellationToken ) )
244+ public Task KillContainerAsync ( string id , ContainerKillParameters parameters , CancellationToken cancellationToken = default )
257245 {
258246 if ( string . IsNullOrEmpty ( id ) )
259247 {
@@ -280,7 +268,7 @@ public Task RenameContainerAsync(string id, ContainerRenameParameters parameters
280268 return _client . MakeRequestAsync ( new [ ] { NoSuchContainerHandler } , HttpMethod . Post , $ "containers/{ id } /rename", queryParameters , cancellationToken ) ;
281269 }
282270
283- public Task PauseContainerAsync ( string id , CancellationToken cancellationToken = default ( CancellationToken ) )
271+ public Task PauseContainerAsync ( string id , CancellationToken cancellationToken = default )
284272 {
285273 if ( string . IsNullOrEmpty ( id ) )
286274 {
@@ -290,7 +278,7 @@ public Task RenameContainerAsync(string id, ContainerRenameParameters parameters
290278 return _client . MakeRequestAsync ( new [ ] { NoSuchContainerHandler } , HttpMethod . Post , $ "containers/{ id } /pause", cancellationToken ) ;
291279 }
292280
293- public Task UnpauseContainerAsync ( string id , CancellationToken cancellationToken = default ( CancellationToken ) )
281+ public Task UnpauseContainerAsync ( string id , CancellationToken cancellationToken = default )
294282 {
295283 if ( string . IsNullOrEmpty ( id ) )
296284 {
@@ -300,7 +288,7 @@ public Task RenameContainerAsync(string id, ContainerRenameParameters parameters
300288 return _client . MakeRequestAsync ( new [ ] { NoSuchContainerHandler } , HttpMethod . Post , $ "containers/{ id } /unpause", cancellationToken ) ;
301289 }
302290
303- public async Task < MultiplexedStream > AttachContainerAsync ( string id , bool tty , ContainerAttachParameters parameters , CancellationToken cancellationToken = default ( CancellationToken ) )
291+ public async Task < MultiplexedStream > AttachContainerAsync ( string id , ContainerAttachParameters parameters , CancellationToken cancellationToken = default )
304292 {
305293 if ( string . IsNullOrEmpty ( id ) )
306294 {
@@ -313,11 +301,17 @@ public Task RenameContainerAsync(string id, ContainerRenameParameters parameters
313301 }
314302
315303 var queryParameters = new QueryString < ContainerAttachParameters > ( parameters ) ;
316- var result = await _client . MakeRequestForStreamAsync ( new [ ] { NoSuchContainerHandler } , HttpMethod . Post , $ "containers/{ id } /attach", queryParameters , null , null , cancellationToken ) . ConfigureAwait ( false ) ;
317- return new MultiplexedStream ( result , ! tty ) ;
304+
305+ var containerInspectResponse = await InspectContainerAsync ( id , cancellationToken )
306+ . ConfigureAwait ( false ) ;
307+
308+ var stream = await _client . MakeRequestForHijackedStreamAsync ( new [ ] { NoSuchContainerHandler } , HttpMethod . Post , $ "containers/{ id } /attach", queryParameters , null , null , cancellationToken )
309+ . ConfigureAwait ( false ) ;
310+
311+ return new MultiplexedStream ( stream , ! containerInspectResponse . Config . Tty ) ;
318312 }
319313
320- public async Task < ContainerWaitResponse > WaitContainerAsync ( string id , CancellationToken cancellationToken = default ( CancellationToken ) )
314+ public async Task < ContainerWaitResponse > WaitContainerAsync ( string id , CancellationToken cancellationToken = default )
321315 {
322316 if ( string . IsNullOrEmpty ( id ) )
323317 {
@@ -327,7 +321,7 @@ public Task RenameContainerAsync(string id, ContainerRenameParameters parameters
327321 return await _client . MakeRequestAsync < ContainerWaitResponse > ( new [ ] { NoSuchContainerHandler } , HttpMethod . Post , $ "containers/{ id } /wait", null , null , null , TimeSpan . FromMilliseconds ( Timeout . Infinite ) , cancellationToken ) . ConfigureAwait ( false ) ;
328322 }
329323
330- public Task RemoveContainerAsync ( string id , ContainerRemoveParameters parameters , CancellationToken cancellationToken = default ( CancellationToken ) )
324+ public Task RemoveContainerAsync ( string id , ContainerRemoveParameters parameters , CancellationToken cancellationToken = default )
331325 {
332326 if ( string . IsNullOrEmpty ( id ) )
333327 {
@@ -343,7 +337,7 @@ public Task RenameContainerAsync(string id, ContainerRenameParameters parameters
343337 return _client . MakeRequestAsync ( new [ ] { NoSuchContainerHandler } , HttpMethod . Delete , $ "containers/{ id } ", queryParameters , cancellationToken ) ;
344338 }
345339
346- public async Task < GetArchiveFromContainerResponse > GetArchiveFromContainerAsync ( string id , GetArchiveFromContainerParameters parameters , bool statOnly , CancellationToken cancellationToken = default ( CancellationToken ) )
340+ public async Task < GetArchiveFromContainerResponse > GetArchiveFromContainerAsync ( string id , GetArchiveFromContainerParameters parameters , bool statOnly , CancellationToken cancellationToken = default )
347341 {
348342 if ( string . IsNullOrEmpty ( id ) )
349343 {
@@ -372,7 +366,7 @@ public Task RenameContainerAsync(string id, ContainerRenameParameters parameters
372366 } ;
373367 }
374368
375- public Task ExtractArchiveToContainerAsync ( string id , ContainerPathStatParameters parameters , Stream stream , CancellationToken cancellationToken = default ( CancellationToken ) )
369+ public Task ExtractArchiveToContainerAsync ( string id , ContainerPathStatParameters parameters , Stream stream , CancellationToken cancellationToken = default )
376370 {
377371 if ( string . IsNullOrEmpty ( id ) )
378372 {
@@ -396,7 +390,7 @@ public async Task<ContainersPruneResponse> PruneContainersAsync(ContainersPruneP
396390 return await _client . MakeRequestAsync < ContainersPruneResponse > ( _client . NoErrorHandlers , HttpMethod . Post , "containers/prune" , queryParameters , cancellationToken ) . ConfigureAwait ( false ) ;
397391 }
398392
399- public async Task < ContainerUpdateResponse > UpdateContainerAsync ( string id , ContainerUpdateParameters parameters , CancellationToken cancellationToken = default ( CancellationToken ) )
393+ public async Task < ContainerUpdateResponse > UpdateContainerAsync ( string id , ContainerUpdateParameters parameters , CancellationToken cancellationToken = default )
400394 {
401395 if ( string . IsNullOrEmpty ( id ) )
402396 {
0 commit comments