/
HttpClientForm.java
219 lines (198 loc) · 5.57 KB
/
HttpClientForm.java
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
/*
* Copyright (c) 2017-2023 VMware, Inc. or its affiliates, All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package reactor.netty.http.client;
import java.io.File;
import java.io.InputStream;
import java.nio.charset.Charset;
import io.netty.handler.codec.http.multipart.HttpDataFactory;
import io.netty.handler.codec.http.multipart.HttpPostRequestEncoder;
import reactor.util.annotation.Nullable;
/**
* An HTTP Form builder.
*/
public interface HttpClientForm {
/**
* Add an HTTP Form attribute.
*
* @param name Attribute name
* @param value Attribute value
*
* @return this builder
*/
HttpClientForm attr(String name, String value);
/**
* Set the Form {@link Charset}.
*
* @param charset form charset
*
* @return this builder
*/
HttpClientForm charset(Charset charset);
/**
* Should file attributes be cleaned and eventually removed from disk.
* Default to false.
*
* @param clean true if cleaned on termination (successful or failed)
*
* @return this builder
*/
HttpClientForm cleanOnTerminate(boolean clean);
/**
* Set Form encoding.
*
* @param mode the encoding mode for this form encoding
* @return this builder
*/
HttpClientForm encoding(HttpPostRequestEncoder.EncoderMode mode);
/**
* Set Upload factories (allows memory threshold configuration).
*
* @param factory the new {@link HttpDataFactory} to use
* @return this builder
*/
HttpClientForm factory(HttpDataFactory factory);
/**
* Add an HTTP File Upload attribute.
*
* @param name File name
* @param file File reference
*
* @return this builder
*/
HttpClientForm file(String name, File file);
/**
* Add an HTTP File Upload attribute.
*
* @param name File name
* @param stream File content as InputStream
*
* @return this builder
*/
HttpClientForm file(String name, InputStream stream);
/**
* Add an HTTP File Upload attribute.
*
* @param name File name
* @param file File reference
* @param contentType File mime-type
*
* @return this builder
*/
default HttpClientForm file(String name, File file, @Nullable String contentType) {
return file(name, file.getName(), file, contentType);
}
/**
* Add an HTTP File Upload attribute.
*
* @param name File name
* @param filename File name to override origin name
* @param file File reference
* @param contentType File mime-type
*
* @return this builder
*/
HttpClientForm file(String name, String filename, File file, @Nullable String contentType);
/**
* Add an HTTP File Upload attribute.
*
* @param name File name
* @param stream File content as InputStream
* @param contentType File mime-type
*
* @return this builder
*/
default HttpClientForm file(String name, InputStream stream, @Nullable String contentType) {
return file(name, "", stream, contentType);
}
/**
* Add an HTTP File Upload attribute.
*
* @param name File name
* @param filename File name to override origin name
* @param stream File content as InputStream
* @param contentType File mime-type
*
* @return this builder
*/
HttpClientForm file(String name, String filename, InputStream stream, @Nullable String contentType);
/**
* Add an HTTP File Upload attribute.
*
* @param name File name
* @param files File references
* @param contentTypes File mime-types in the same order than file references
*
* @return this builder
*/
HttpClientForm files(String name, File[] files, String[] contentTypes);
/**
* Add an HTTP File Upload attribute.
*
* @param name File name
* @param files File references
* @param contentTypes File mime-type in the same order than file references
* @param textFiles Plain-Text transmission in the same order than file references
*
* @return this builder
*/
HttpClientForm files(String name, File[] files, String[] contentTypes, boolean[] textFiles);
/**
* Define if this request will be encoded as Multipart.
*
* @param multipart should this form be encoded as Multipart
*
* @return this builder
*/
HttpClientForm multipart(boolean multipart);
/**
* Add an HTTP File Upload attribute for a text file.
*
* @param name Text file name
* @param file Text File reference
*
* @return this builder
*/
HttpClientForm textFile(String name, File file);
/**
* Add an HTTP File Upload attribute for a text file.
*
* @param name Text file name
* @param stream Text file content as InputStream
*
* @return this builder
*/
HttpClientForm textFile(String name, InputStream stream);
/**
* Add an HTTP File Upload attribute for a text file.
*
* @param name Text file name
* @param file Text File reference
* @param contentType Text file mime-type
*
* @return this builder
*/
HttpClientForm textFile(String name, File file, @Nullable String contentType);
/**
* Add an HTTP File Upload attribute for a text file.
*
* @param name Text file name
* @param inputStream Text file content as InputStream
* @param contentType Text file mime-type
*
* @return this builder
*/
HttpClientForm textFile(String name, InputStream inputStream, @Nullable String contentType);
}