Skip to content

Commit a489dee

Browse files
committed
Update documentation for HttpOpener. (#463)
1 parent ea537d7 commit a489dee

File tree

1 file changed

+48
-30
lines changed

1 file changed

+48
-30
lines changed

metafacture-io/src/main/java/org/metafacture/io/HttpOpener.java

Lines changed: 48 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -50,18 +50,22 @@
5050
@FluxCommand("open-http")
5151
public final class HttpOpener extends DefaultObjectPipe<String, ObjectReceiver<Reader>> {
5252

53-
private static final Pattern HEADER_FIELD_SEPARATOR = Pattern.compile("\n");
54-
private static final Pattern HEADER_VALUE_SEPARATOR = Pattern.compile(":");
53+
public static final String ACCEPT_DEFAULT = "*/*";
54+
public static final String ACCEPT_HEADER = "accept";
55+
public static final String CONTENT_TYPE_HEADER = "content-type";
56+
public static final String DEFAULT_PREFIX = "ERROR: ";
57+
public static final String ENCODING_DEFAULT = "UTF-8";
58+
public static final String ENCODING_HEADER = "accept-charset";
59+
public static final String INPUT_DESIGNATOR = "@-";
5560

56-
private static final String ACCEPT_DEFAULT = "*/*";
57-
private static final String ACCEPT_HEADER = "accept";
58-
private static final String CONTENT_TYPE_HEADER = "content-type";
59-
private static final String DEFAULT_PREFIX = "ERROR: ";
60-
private static final String ENCODING_DEFAULT = "UTF-8";
61-
private static final String ENCODING_HEADER = "accept-charset";
62-
private static final String INPUT_DESIGNATOR = "@-";
61+
public static final String DEFAULT_METHOD_NAME = "GET";
62+
public static final Method DEFAULT_METHOD = Method.valueOf(DEFAULT_METHOD_NAME);
6363

64-
private static final Method DEFAULT_METHOD = Method.GET;
64+
public static final String HEADER_FIELD_SEPARATOR = "\n";
65+
public static final String HEADER_VALUE_SEPARATOR = ":";
66+
67+
private static final Pattern HEADER_FIELD_SEPARATOR_PATTERN = Pattern.compile(HEADER_FIELD_SEPARATOR);
68+
private static final Pattern HEADER_VALUE_SEPARATOR_PATTERN = Pattern.compile(HEADER_VALUE_SEPARATOR);
6569

6670
private static final int SUCCESS_CODE_MIN = 200;
6771
private static final int SUCCESS_CODE_MAX = 399;
@@ -124,18 +128,24 @@ public HttpOpener() {
124128
}
125129

126130
/**
127-
* Sets the HTTP accept header value. This is a mime-type such as text/plain
128-
* or text/html. The default value of the accept is *&#47;* which means
129-
* any mime-type.
131+
* Sets the HTTP {@value ACCEPT_HEADER} header value. This is a MIME type
132+
* such as {@code text/plain} or {@code application/json}. The default
133+
* value for the accept header is {@value ACCEPT_DEFAULT} which means
134+
* any MIME type.
130135
*
131-
* @param accept mime-type to use for the HTTP accept header
136+
* @param accept MIME type to use for the HTTP accept header
132137
*/
133138
public void setAccept(final String accept) {
134139
setHeader(ACCEPT_HEADER, accept);
135140
}
136141

137142
/**
138-
* Sets the HTTP request body.
143+
* Sets the HTTP request body. The default value for the request body is
144+
* {@value INPUT_DESIGNATOR} <i>if the {@link #setMethod(Method) request
145+
* method} accepts a request body</i>, which means it will use the {@link
146+
* #process(String) input data} data as request body <i>if the input has
147+
* not already been used</i>; otherwise, no request body will be set by
148+
* default.
139149
*
140150
* @param body the request body
141151
*/
@@ -144,20 +154,20 @@ public void setBody(final String body) {
144154
}
145155

146156
/**
147-
* Sets the HTTP content type header. This is a mime-type such as text/plain,
148-
* text/html. The default is application/json.
157+
* Sets the HTTP {@value CONTENT_TYPE_HEADER} header value. This is a
158+
* MIME type such as {@code text/plain} or {@code application/json}.
149159
*
150-
* @param contentType mime-type to use for the HTTP contentType header
160+
* @param contentType MIME type to use for the HTTP content-type header
151161
*/
152162
public void setContentType(final String contentType) {
153163
setHeader(CONTENT_TYPE_HEADER, contentType);
154164
}
155165

156166
/**
157-
* Sets the preferred encoding of the HTTP response. This value is in the
158-
* accept-charset header. Additonally, the encoding is used for reading the
159-
* HTTP resonse if it does not specify an encoding. The default value for
160-
* the encoding is UTF-8.
167+
* Sets the HTTP {@value ENCODING_HEADER} header value. This is the
168+
* preferred encoding for the HTTP response. Additionally, the encoding
169+
* is used for reading the HTTP response if it does not specify a content
170+
* encoding. The default for the encoding is {@value ENCODING_DEFAULT}.
161171
*
162172
* @param encoding name of the encoding used for the accept-charset HTTP
163173
* header
@@ -167,7 +177,8 @@ public void setEncoding(final String encoding) {
167177
}
168178

169179
/**
170-
* Sets the error prefix.
180+
* Sets the error prefix. The default error prefix is
181+
* {@value DEFAULT_PREFIX}.
171182
*
172183
* @param errorPrefix the error prefix
173184
*/
@@ -176,14 +187,18 @@ public void setErrorPrefix(final String errorPrefix) {
176187
}
177188

178189
/**
179-
* Sets a request property, or multiple request properties separated by
180-
* {@code \n}.
190+
* Sets a request property (header), or multiple request properties
191+
* separated by {@value HEADER_FIELD_SEPARATOR}. Header name and value
192+
* are separated by {@value HEADER_VALUE_SEPARATOR}. The header name is
193+
* case-insensitive.
181194
*
182195
* @param header request property line
196+
*
197+
* @see #setHeader(String, String)
183198
*/
184199
public void setHeader(final String header) {
185-
Arrays.stream(HEADER_FIELD_SEPARATOR.split(header)).forEach(h -> {
186-
final String[] parts = HEADER_VALUE_SEPARATOR.split(h, 2);
200+
Arrays.stream(HEADER_FIELD_SEPARATOR_PATTERN.split(header)).forEach(h -> {
201+
final String[] parts = HEADER_VALUE_SEPARATOR_PATTERN.split(h, 2);
187202
if (parts.length == 2) {
188203
setHeader(parts[0], parts[1].trim());
189204
}
@@ -194,7 +209,7 @@ public void setHeader(final String header) {
194209
}
195210

196211
/**
197-
* Sets a request property.
212+
* Sets a request property (header). The header name is case-insensitive.
198213
*
199214
* @param key request property key
200215
* @param value request property value
@@ -204,7 +219,8 @@ public void setHeader(final String key, final String value) {
204219
}
205220

206221
/**
207-
* Sets the HTTP request method.
222+
* Sets the HTTP request method. The default request method is
223+
* {@value DEFAULT_METHOD_NAME}.
208224
*
209225
* @param method the request method
210226
*/
@@ -213,7 +229,9 @@ public void setMethod(final Method method) {
213229
}
214230

215231
/**
216-
* Sets the HTTP request URL.
232+
* Sets the HTTP request URL. The default value for the request URL is
233+
* {@value INPUT_DESIGNATOR}, which means it will use the {@link
234+
* #process(String) input data} as request URL.
217235
*
218236
* @param url the request URL
219237
*/

0 commit comments

Comments
 (0)