@@ -26,32 +26,79 @@ public interface HttpRequest {
2626
2727 public HttpRequest addHeader (String name , String value );
2828
29- public HttpRequest addParameter (String name , String value );
29+ /**
30+ * Add parameter which will be appended to the url query.
31+ */
32+ public HttpRequest addQueryParameter (String name , String value );
3033
31- public HttpRequest addFile (String name , File file );
34+ /**
35+ * Add parameter to the request form (either urlencoded or multipart).
36+ */
37+ public HttpRequest addFormPart (String name , String value );
3238
33- public HttpRequest addFile (String name , InputStream stream );
39+ /**
40+ * Add file form parameter with specified content type and file name to the
41+ * reqeust converting it into a multipart form .
42+ */
43+ public HttpRequest addFilePart (String name , File file ,
44+ String contentType , String fileName );
3445
35- public HttpRequest addFormField (String name , Object data , String contentType , String fileName );
46+ /**
47+ * Add file form parameter to the request converting it into a multipart
48+ * form. Content type will be set to "application/octet-stream" and file
49+ * name to the name of the file.
50+ */
51+ public default HttpRequest addFilePart (String name , File file ) {
52+ return addFile (name , file , "application/octet-stream" , file .getName ());
53+ }
3654
37- boolean removeFormField (String name );
55+ /**
56+ * Add file form parameter to the request converting it into a multipart
57+ * form.
58+ */
59+ public HttpRequest addFilePart (String name , InputStream stream ,
60+ String contentType , String fileName );
61+
62+ /**
63+ * Add file form parameter to the reqeust converting it into a multipart form.
64+ * The content type will be set to "application/octet-stream" and file name to "file".
65+ */
66+ public default HttpRequest addFilePart (String name , InputStream stream ) {
67+ return addFileParameter (name , stream , "application/octet-stream" , "file" )
68+ }
69+
70+ /**
71+ * Remove all query parameters having the specified name from the request.
72+ */
73+ public HttpRequest clearQueryParameters (String name );
74+
75+ /**
76+ * Remove all form parameters having the specified name.
77+ */
78+ public HttpRequest clearFormParts (String name );
3879
3980 /**
4081 * Send the request to the server and return the response.
4182 */
4283 public HttpResponse execute () throws IOException ;
4384
44- public void executeAsync (Consumer <HttpResponse > success ,
85+ public void executeAsync (Consumer <HttpResponse > success ,
4586 BiConsumer <HttpResponse , ? super IOException > failure ,
4687 BiConsumer <HttpResponse , ? super IOException > always );
4788 }
4889
4990 public interface HttpResponse extends Closeable {
91+
92+ /**
93+ * Get the status code of the response as per RFC 2616.
94+ *
95+ * @return
96+ */
5097 public int getStatusCode ();
5198
5299 /**
53- * Get the response headers, combining same-name headers with commas, preserving
54- * order, as per RFC 2616
100+ * Get the response headers, combining same-name headers with commas,
101+ * preserving order, as per RFC 2616
55102 *
56103 * @return
57104 */
@@ -83,34 +130,33 @@ public default void close() throws IOException {
83130 }
84131
85132 /**
86- * Initialises the GET request builder. Usually they have no request body and
133+ * Creates a new GET request. They usually have no body and
87134 * parameters are passed in the URL query.
88135 */
89136 public HttpRequest get (URI uri );
90137
91138 /**
92- * Initialises the GET request builder . They have no request body and parameters
93- * are passed in the URL query. They are identical to GET requests, the only
94- * difference is that the returned response contains headers only .
139+ * Creates a new HEAD request . They have no request body and
140+ * parameters are passed in the URL query. They are identical to GET requests,
141+ * except they receive no response body .
95142 */
96143 public HttpRequest head (URI uri );
97144
98145 /**
99- * Initialises the POST request builder . Usually they contain data in the
146+ * Creates a new POST request. Usually they pass data in the
100147 * request body either as a urlencoded form, a multipart form or raw bytes.
101- * Currently, we only care about the multipart form .
148+ * Currently, we only care about the multipart and urlencoded forms .
102149 */
103150 public HttpRequest post (URI uri );
104151
105152 /**
106- * Initialises the PUT request builder which construct the same way as POST. The
107- * only difference is the request method.
153+ * Creates a new PUT request which is constructed the same way as POST.
108154 */
109155 public HttpRequest put (URI uri );
110156
111157 /**
112- * Initialises the DELETE request builder. The DELETE requests have no body and
113- * parameters are passed in the URL query, just like GET.
158+ * Creates a new DELETE request. THey have have no body
159+ * and parameters are passed in the URL query, just like GET.
114160 */
115161 public HttpRequest delete (URI uri );
116162
0 commit comments