Skip to content

Commit 75c7ef5

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

File tree

1 file changed

+51
-30
lines changed

1 file changed

+51
-30
lines changed

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

Lines changed: 51 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,27 @@ 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.
149+
*
150+
* <p>If a request body has been set, but the request method does not
151+
* accept a body, the method <i>may</i> be changed to {@code POST}.
139152
*
140153
* @param body the request body
141154
*/
@@ -144,20 +157,20 @@ public void setBody(final String body) {
144157
}
145158

146159
/**
147-
* Sets the HTTP content type header. This is a mime-type such as text/plain,
148-
* text/html. The default is application/json.
160+
* Sets the HTTP {@value CONTENT_TYPE_HEADER} header value. This is a
161+
* MIME type such as {@code text/plain} or {@code application/json}.
149162
*
150-
* @param contentType mime-type to use for the HTTP contentType header
163+
* @param contentType MIME type to use for the HTTP content-type header
151164
*/
152165
public void setContentType(final String contentType) {
153166
setHeader(CONTENT_TYPE_HEADER, contentType);
154167
}
155168

156169
/**
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.
170+
* Sets the HTTP {@value ENCODING_HEADER} header value. This is the
171+
* preferred encoding for the HTTP response. Additionally, the encoding
172+
* is used for reading the HTTP response if it does not specify a content
173+
* encoding. The default for the encoding is {@value ENCODING_DEFAULT}.
161174
*
162175
* @param encoding name of the encoding used for the accept-charset HTTP
163176
* header
@@ -167,7 +180,8 @@ public void setEncoding(final String encoding) {
167180
}
168181

169182
/**
170-
* Sets the error prefix.
183+
* Sets the error prefix. The default error prefix is
184+
* {@value DEFAULT_PREFIX}.
171185
*
172186
* @param errorPrefix the error prefix
173187
*/
@@ -176,14 +190,18 @@ public void setErrorPrefix(final String errorPrefix) {
176190
}
177191

178192
/**
179-
* Sets a request property, or multiple request properties separated by
180-
* {@code \n}.
193+
* Sets a request property (header), or multiple request properties
194+
* separated by {@value HEADER_FIELD_SEPARATOR}. Header name and value
195+
* are separated by {@value HEADER_VALUE_SEPARATOR}. The header name is
196+
* case-insensitive.
181197
*
182198
* @param header request property line
199+
*
200+
* @see #setHeader(String, String)
183201
*/
184202
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);
203+
Arrays.stream(HEADER_FIELD_SEPARATOR_PATTERN.split(header)).forEach(h -> {
204+
final String[] parts = HEADER_VALUE_SEPARATOR_PATTERN.split(h, 2);
187205
if (parts.length == 2) {
188206
setHeader(parts[0], parts[1].trim());
189207
}
@@ -194,7 +212,7 @@ public void setHeader(final String header) {
194212
}
195213

196214
/**
197-
* Sets a request property.
215+
* Sets a request property (header). The header name is case-insensitive.
198216
*
199217
* @param key request property key
200218
* @param value request property value
@@ -204,7 +222,8 @@ public void setHeader(final String key, final String value) {
204222
}
205223

206224
/**
207-
* Sets the HTTP request method.
225+
* Sets the HTTP request method. The default request method is
226+
* {@value DEFAULT_METHOD_NAME}.
208227
*
209228
* @param method the request method
210229
*/
@@ -213,7 +232,9 @@ public void setMethod(final Method method) {
213232
}
214233

215234
/**
216-
* Sets the HTTP request URL.
235+
* Sets the HTTP request URL. The default value for the request URL is
236+
* {@value INPUT_DESIGNATOR}, which means it will use the {@link
237+
* #process(String) input data} as request URL.
217238
*
218239
* @param url the request URL
219240
*/

0 commit comments

Comments
 (0)