forked from docker-java/docker-java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerHttpClient.java
More file actions
90 lines (68 loc) · 2.12 KB
/
Copy pathDockerHttpClient.java
File metadata and controls
90 lines (68 loc) · 2.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
package com.github.dockerjava.transport;
import org.immutables.value.Value;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.io.ByteArrayInputStream;
import java.io.Closeable;
import java.io.InputStream;
import java.util.List;
import java.util.Map;
public interface DockerHttpClient extends Closeable {
Response execute(Request request);
interface Response extends Closeable {
int getStatusCode();
Map<String, List<String>> getHeaders();
InputStream getBody();
@Override
void close();
@Nullable
default String getHeader(@Nonnull String name) {
for (Map.Entry<String, List<String>> entry : getHeaders().entrySet()) {
if (name.equalsIgnoreCase(entry.getKey())) {
List<String> values = entry.getValue();
return values.isEmpty() ? null : values.get(0);
}
}
return null;
}
}
@Value.Immutable
@Value.Style(
visibility = Value.Style.ImplementationVisibility.PACKAGE,
overshadowImplementation = true,
depluralize = true
)
abstract class Request {
public enum Method {
GET,
POST,
PUT,
DELETE,
OPTIONS,
PATCH,
}
public static class Builder extends ImmutableRequest.Builder {
public Builder method(Method method) {
return method(method.name());
}
}
public static Builder builder() {
return new Builder();
}
public abstract String method();
public abstract String path();
@Nullable
@Value.Default
public InputStream body() {
byte[] bodyBytes = bodyBytes();
return bodyBytes != null
? new ByteArrayInputStream(bodyBytes)
: null;
}
@Nullable
public abstract byte[] bodyBytes();
@Nullable
public abstract InputStream hijackedInput();
public abstract Map<String, String> headers();
}
}