Skip to content

Commit 83101b7

Browse files
committed
Rename methods dealing with request form parts and update docs.
1 parent ddaba2b commit 83101b7

File tree

2 files changed

+28
-18
lines changed

2 files changed

+28
-18
lines changed

sources/net.sf.j2s.java.core/src/javajs/http/HttpClient.java

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -34,43 +34,48 @@ public interface HttpRequest {
3434
/**
3535
* Add parameter to the request form (either urlencoded or multipart).
3636
*/
37-
public HttpRequest addFormParameter(String name, String value);
37+
public HttpRequest addFormPart(String name, String value);
3838

3939
/**
4040
* Add file form parameter with specified content type and file name to the
4141
* reqeust converting it into a multipart form .
4242
*/
43-
public HttpRequest addFileParameter(String name, File file,
43+
public HttpRequest addFilePart(String name, File file,
4444
String contentType, String fileName);
4545

4646
/**
4747
* Add file form parameter to the request converting it into a multipart
4848
* form. Content type will be set to "application/octet-stream" and file
4949
* name to the name of the file.
5050
*/
51-
public default HttpRequest addFileParameter(String name, File file) {
51+
public default HttpRequest addFilePart(String name, File file) {
5252
return addFile(name, file, "application/octet-stream", file.getName());
5353
}
5454

5555
/**
5656
* Add file form parameter to the request converting it into a multipart
5757
* form.
5858
*/
59-
public HttpRequest addFileParameter(String name, InputStream stream,
59+
public HttpRequest addFilePart(String name, InputStream stream,
6060
String contentType, String fileName);
6161

6262
/**
6363
* Add file form parameter to the reqeust converting it into a multipart form.
6464
* The content type will be set to "application/octet-stream" and file name to "file".
6565
*/
66-
public default HttpRequest addFileParameter(String name, InputStream stream) {
66+
public default HttpRequest addFilePart(String name, InputStream stream) {
6767
return addFileParameter(name, stream, "application/octet-stream", "file")
6868
}
6969

7070
/**
71-
* Remove all parameters having the specified name from the reuqest.
71+
* Remove all query parameters having the specified name from the request.
7272
*/
73-
public HttpRequest clearParameter(String name);
73+
public HttpRequest clearQueryParameters(String name);
74+
75+
/**
76+
* Remove all form parameters having the specified name.
77+
*/
78+
public HttpRequest clearFormParts(String name);
7479

7580
/**
7681
* Send the request to the server and return the response.
@@ -125,33 +130,32 @@ public default void close() throws IOException {
125130
}
126131

127132
/**
128-
* Initialises the GET request builder. Usually they have no request body and
133+
* Creates a new GET request. They usually have no body and
129134
* parameters are passed in the URL query.
130135
*/
131136
public HttpRequest get(URI uri);
132137

133138
/**
134-
* Initialises the GET request builder. They have no request body and
139+
* Creates a new HEAD request. They have no request body and
135140
* parameters are passed in the URL query. They are identical to GET requests,
136-
* the only difference is that the returned response contains headers only.
141+
* except they receive no response body.
137142
*/
138143
public HttpRequest head(URI uri);
139144

140145
/**
141-
* Initialises the POST request builder. Usually they contain data in the
146+
* Creates a new POST request. Usually they pass data in the
142147
* request body either as a urlencoded form, a multipart form or raw bytes.
143-
* Currently, we only care about the multipart form.
148+
* Currently, we only care about the multipart and urlencoded forms.
144149
*/
145150
public HttpRequest post(URI uri);
146151

147152
/**
148-
* Initialises the PUT request builder which construct the same way as POST.
149-
* The only difference is the request method.
153+
* Creates a new PUT request which is constructed the same way as POST.
150154
*/
151155
public HttpRequest put(URI uri);
152156

153157
/**
154-
* Initialises the DELETE request builder. The DELETE requests have no body
158+
* Creates a new DELETE request. THey have have no body
155159
* and parameters are passed in the URL query, just like GET.
156160
*/
157161
public HttpRequest delete(URI uri);

sources/net.sf.j2s.java.core/src/javajs/http/SimpleHttpClient.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import java.util.function.Consumer;
2121
import java.util.function.Function;
2222

23+
2324
/**
2425
* SwingJS implementation of javajs.http.HttpClient and associated classes.
2526
*
@@ -202,18 +203,23 @@ public HttpRequest addHeader(String name, String value) {
202203
}
203204

204205
@Override
205-
public HttpRequest addFormParameter(String name, String value) {
206+
public HttpRequest addQueryParameter(String name, String value) {
207+
// TODO: implement adding parameters to url query
208+
}
209+
210+
@Override
211+
public HttpRequest addFormPart(String name, String value) {
206212
return addFormField(name, value, null, null);
207213
}
208214

209215
@Override
210-
public HttpRequest addFileParameter(String name, File file, String contentType, String fileName) {
216+
public HttpRequest addFilePart(String name, File file, String contentType, String fileName) {
211217
return addFormField(name, toBytes(file), contentType, fileName);
212218
}
213219

214220

215221
@Override
216-
public HttpRequest addFileParameter(String name, InputStream stream, String contentType, String fileName) {
222+
public HttpRequest addFilePart(String name, InputStream stream, String contentType, String fileName) {
217223
return addFormField(name, toBytes(stream), contentType, fileName);
218224
}
219225

0 commit comments

Comments
 (0)