Skip to content

Commit a16f1d9

Browse files
authored
Merge pull request quarkusio#47820 from geoand/client-multipart-polish
Polish client multipart handling
2 parents afbcddb + db2f9b3 commit a16f1d9

File tree

3 files changed

+8
-13
lines changed

3 files changed

+8
-13
lines changed

independent-projects/resteasy-reactive/client/runtime/src/main/java/org/jboss/resteasy/reactive/client/handlers/ClientSendRequestHandler.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -474,14 +474,13 @@ private int defaultPort(boolean isHttps) {
474474

475475
private QuarkusMultipartFormUpload setMultipartHeadersAndPrepareBody(HttpClientRequest httpClientRequest,
476476
RestClientRequestContext state) throws Exception {
477-
if (!(state.getEntity().getEntity() instanceof QuarkusMultipartForm)) {
477+
if (!(state.getEntity().getEntity() instanceof QuarkusMultipartForm multipartForm)) {
478478
throw new IllegalArgumentException(
479479
"Multipart form upload expects an entity of type MultipartForm, got: " + state.getEntity().getEntity());
480480
}
481481

482482
MultivaluedMap<String, String> headerMap = state.getRequestHeadersAsMap();
483483
updateRequestHeadersFromConfig(state, headerMap);
484-
QuarkusMultipartForm multipartForm = (QuarkusMultipartForm) state.getEntity().getEntity();
485484
multipartForm.preparePojos(state);
486485

487486
Object property = state.getConfiguration().getProperty(QuarkusRestClientProperties.MULTIPART_ENCODER_MODE);

independent-projects/resteasy-reactive/client/runtime/src/main/java/org/jboss/resteasy/reactive/client/impl/multipart/PausableHttpPostRequestEncoder.java

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -511,8 +511,7 @@ public void addBodyHttpData(InterfaceHttpData data) throws ErrorDataEncoderExcep
511511
}
512512
bodyListDatas.add(checkNotNull(data, "data"));
513513
if (!isMultipart) {
514-
if (data instanceof Attribute) {
515-
Attribute attribute = (Attribute) data;
514+
if (data instanceof Attribute attribute) {
516515
try {
517516
// name=value& with encoded name and attribute
518517
String key = encodeAttribute(attribute.getName(), charset);
@@ -523,9 +522,8 @@ public void addBodyHttpData(InterfaceHttpData data) throws ErrorDataEncoderExcep
523522
} catch (IOException e) {
524523
throw new ErrorDataEncoderException(e);
525524
}
526-
} else if (data instanceof FileUpload) {
525+
} else if (data instanceof FileUpload fileUpload) {
527526
// since not Multipart, only name=filename => Attribute
528-
FileUpload fileUpload = (FileUpload) data;
529527
// name=filename& with encoded name and filename
530528
String key = encodeAttribute(fileUpload.getName(), charset);
531529
String value = encodeAttribute(fileUpload.getFilename(), charset);
@@ -567,7 +565,7 @@ public void addBodyHttpData(InterfaceHttpData data) throws ErrorDataEncoderExcep
567565
* if duringmixedmode: endmixedmultipart + endmultipart
568566
* else only endmultipart
569567
*/
570-
if (data instanceof Attribute) {
568+
if (data instanceof Attribute attribute) {
571569
if (duringMixedMode) {
572570
QuarkusInternalAttribute internal = new QuarkusInternalAttribute(charset);
573571
internal.addValue("\r\n--" + multipartMixedBoundary + "--");
@@ -583,7 +581,6 @@ public void addBodyHttpData(InterfaceHttpData data) throws ErrorDataEncoderExcep
583581
}
584582
internal.addValue("--" + multipartDataBoundary + "\r\n");
585583
// content-disposition: form-data; name="field1"
586-
Attribute attribute = (Attribute) data;
587584
internal.addValue(HttpHeaderNames.CONTENT_DISPOSITION + ": " + HttpHeaderValues.FORM_DATA + "; "
588585
+ HttpHeaderValues.NAME + "=\"" + attribute.getName() + "\"\r\n");
589586
// Add Content-Length: xxx
@@ -602,8 +599,7 @@ public void addBodyHttpData(InterfaceHttpData data) throws ErrorDataEncoderExcep
602599
multipartHttpDatas.add(internal);
603600
multipartHttpDatas.add(data);
604601
globalBodySize += attribute.length() + internal.size();
605-
} else if (data instanceof FileUpload) {
606-
FileUpload fileUpload = (FileUpload) data;
602+
} else if (data instanceof FileUpload fileUpload) {
607603
QuarkusInternalAttribute internal = new QuarkusInternalAttribute(charset);
608604
if (!multipartHttpDatas.isEmpty()) {
609605
// previously a data field so CRLF
@@ -856,8 +852,7 @@ public HttpRequest finalizeRequest() throws ErrorDataEncoderException {
856852
} else {
857853
// get the only one body and set it to the request
858854
HttpContent chunk = nextChunk();
859-
if (request instanceof FullHttpRequest) {
860-
FullHttpRequest fullRequest = (FullHttpRequest) request;
855+
if (request instanceof FullHttpRequest fullRequest) {
861856
ByteBuf chunkContent = chunk.content();
862857
if (fullRequest.content() != chunkContent && chunkContent != null) {
863858
fullRequest.content().clear().writeBytes(chunkContent);

independent-projects/resteasy-reactive/client/runtime/src/main/java/org/jboss/resteasy/reactive/client/impl/multipart/QuarkusMultipartFormUpload.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@ public QuarkusMultipartFormUpload(Context context,
4747
this.context = context;
4848
this.pending = new InboundBuffer<>(context)
4949
.handler(this::handleChunk)
50-
.drainHandler(v -> run()).pause();
50+
.drainHandler(v -> run())
51+
.pause();
5152
this.request = new DefaultFullHttpRequest(
5253
HttpVersion.HTTP_1_1,
5354
io.netty.handler.codec.http.HttpMethod.POST,

0 commit comments

Comments
 (0)