-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Motivation: HTTP client form submission has been available for ages in Vert.x Web Client exclusively. Since there is no good reason for that, this has been implemented in HTTP client as well. Changes: HTTP client form submission implementation.
- Loading branch information
Showing
13 changed files
with
1,223 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
79 changes: 79 additions & 0 deletions
79
vertx-core/src/main/java/io/vertx/core/http/ClientForm.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
/* | ||
* Copyright (c) 2011-2025 Contributors to the Eclipse Foundation | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 | ||
* which is available at https://www.apache.org/licenses/LICENSE-2.0. | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 | ||
*/ | ||
package io.vertx.core.http; | ||
|
||
import io.vertx.codegen.annotations.Fluent; | ||
import io.vertx.codegen.annotations.GenIgnore; | ||
import io.vertx.codegen.annotations.VertxGen; | ||
import io.vertx.core.MultiMap; | ||
import io.vertx.core.http.impl.ClientMultipartFormImpl; | ||
|
||
import java.nio.charset.Charset; | ||
import java.nio.charset.StandardCharsets; | ||
import java.util.Map; | ||
|
||
/** | ||
* A form: a container for attributes. | ||
*/ | ||
@VertxGen | ||
public interface ClientForm { | ||
|
||
/** | ||
* @return a blank form | ||
*/ | ||
static ClientForm form() { | ||
ClientMultipartFormImpl form = new ClientMultipartFormImpl(false); | ||
form.charset(StandardCharsets.UTF_8); | ||
return form; | ||
} | ||
|
||
/** | ||
* @param initial the initial content of the form | ||
* @return a form populated after the {@code initial} multimap | ||
*/ | ||
static ClientForm form(MultiMap initial) { | ||
ClientMultipartFormImpl form = new ClientMultipartFormImpl(false); | ||
for (Map.Entry<String, String> attribute : initial) { | ||
form.attribute(attribute.getKey(), attribute.getValue()); | ||
} | ||
form.charset(StandardCharsets.UTF_8); | ||
return form; | ||
} | ||
|
||
@Fluent | ||
ClientForm attribute(String name, String value); | ||
|
||
/** | ||
* Set the {@code charset} to use when encoding the form. The default charset is {@link java.nio.charset.StandardCharsets#UTF_8}. | ||
* | ||
* @param charset the charset to use | ||
* @return a reference to this, so the API can be used fluently | ||
*/ | ||
@Fluent | ||
ClientForm charset(String charset); | ||
|
||
/** | ||
* Set the {@code charset} to use when encoding the form. The default charset is {@link java.nio.charset.StandardCharsets#UTF_8}. | ||
* | ||
* @param charset the charset to use | ||
* @return a reference to this, so the API can be used fluently | ||
*/ | ||
@GenIgnore(GenIgnore.PERMITTED_TYPE) | ||
@Fluent | ||
ClientForm charset(Charset charset); | ||
|
||
/** | ||
* @return the charset to use when encoding the form | ||
*/ | ||
@GenIgnore(GenIgnore.PERMITTED_TYPE) | ||
Charset charset(); | ||
|
||
} |
121 changes: 121 additions & 0 deletions
121
vertx-core/src/main/java/io/vertx/core/http/ClientMultipartForm.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
/* | ||
* Copyright (c) 2011-2025 Contributors to the Eclipse Foundation | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 | ||
* which is available at https://www.apache.org/licenses/LICENSE-2.0. | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 | ||
*/ | ||
package io.vertx.core.http; | ||
|
||
import io.vertx.codegen.annotations.Fluent; | ||
import io.vertx.codegen.annotations.GenIgnore; | ||
import io.vertx.codegen.annotations.VertxGen; | ||
import io.vertx.core.buffer.Buffer; | ||
import io.vertx.core.http.impl.ClientMultipartFormImpl; | ||
|
||
import java.nio.charset.Charset; | ||
|
||
/** | ||
* A multipart form, providing file upload capabilities. | ||
* | ||
* @author <a href="mailto:julien@julienviet.com">Julien Viet</a> | ||
*/ | ||
@VertxGen | ||
public interface ClientMultipartForm extends ClientForm { | ||
|
||
/** | ||
* @return a blank multipart form | ||
*/ | ||
static ClientMultipartForm multipartForm() { | ||
return new ClientMultipartFormImpl(true); | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
@Fluent | ||
ClientMultipartForm attribute(String name, String value); | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
@Fluent | ||
ClientMultipartForm charset(String charset); | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
@GenIgnore(GenIgnore.PERMITTED_TYPE) | ||
@Fluent | ||
ClientMultipartForm charset(Charset charset); | ||
|
||
/** | ||
* Allow or disallow multipart mixed encoding when files are sharing the same file name. | ||
* <br/> | ||
* The default value is {@code true}. | ||
* <br/> | ||
* Set to {@code false} if you want to achieve the behavior for <a href="http://www.w3.org/TR/html5/forms.html#multipart-form-data">HTML5</a>. | ||
* | ||
* @param allow {@code true} allows use of multipart mixed encoding | ||
* @return a reference to this, so the API can be used fluently | ||
*/ | ||
@Fluent | ||
ClientMultipartForm mixed(boolean allow); | ||
|
||
/** | ||
* @return whether multipart mixed encoding is allowed | ||
*/ | ||
boolean mixed(); | ||
|
||
/** | ||
* Add a text file upload form data part. | ||
* | ||
* @param name name of the parameter | ||
* @param filename filename of the file | ||
* @param mediaType the MIME type of the file | ||
* @param content the content of the file | ||
* @return a reference to this, so the API can be used fluently | ||
*/ | ||
@Fluent | ||
ClientMultipartForm textFileUpload(String name, String filename, String mediaType, Buffer content); | ||
|
||
/** | ||
* Add a binary file upload form data part. | ||
* | ||
* @param name name of the parameter | ||
* @param filename filename of the file | ||
* @param mediaType the MIME type of the file | ||
* @param content the content of the file | ||
* @return a reference to this, so the API can be used fluently | ||
*/ | ||
@Fluent | ||
ClientMultipartForm binaryFileUpload(String name, String filename, String mediaType, Buffer content); | ||
|
||
/** | ||
* Add a text file upload form data part. | ||
* | ||
* @param name name of the parameter | ||
* @param filename filename of the file | ||
* @param mediaType the MIME type of the file | ||
* @param pathname the pathname of the file | ||
* @return a reference to this, so the API can be used fluently | ||
*/ | ||
@Fluent | ||
ClientMultipartForm textFileUpload(String name, String filename, String mediaType, String pathname); | ||
|
||
/** | ||
* Add a binary file upload form data part. | ||
* | ||
* @param name name of the parameter | ||
* @param filename filename of the file | ||
* @param mediaType the MIME type of the file | ||
* @param pathname the pathname of the file | ||
* @return a reference to this, so the API can be used fluently | ||
*/ | ||
@Fluent | ||
ClientMultipartForm binaryFileUpload(String name, String filename, String mediaType, String pathname); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.