Support for multipart/form-data; charset="utf-8" in Java GSON Generator (#16211)

* Support for multipart/form-data; charset="utf-8"

Previously, it was only checked for an exact equal string, which failed when there were additional options such as charset.

* Update samples
This commit is contained in:
Marc Miltenberger 2023-07-28 18:22:19 +02:00 committed by GitHub
parent 7ca84e5c88
commit adac3b127f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 66 additions and 33 deletions

View File

@ -1426,12 +1426,15 @@ public class ApiClient {
// prepare HTTP request body
RequestBody reqBody;
String contentType = headerParams.get("Content-Type");
String contentTypePure = contentType;
if (contentTypePure != null && contentTypePure.contains(";")) {
contentTypePure = contentType.substring(0, contentType.indexOf(";"));
}
if (!HttpMethod.permitsRequestBody(method)) {
reqBody = null;
} else if ("application/x-www-form-urlencoded".equals(contentType)) {
} else if ("application/x-www-form-urlencoded".equals(contentTypePure)) {
reqBody = buildRequestBodyFormEncoding(formParams);
} else if ("multipart/form-data".equals(contentType)) {
} else if ("multipart/form-data".equals(contentTypePure)) {
reqBody = buildRequestBodyMultipart(formParams);
} else if (body == null) {
if ("DELETE".equals(method)) {

View File

@ -1166,12 +1166,15 @@ public class ApiClient {
// prepare HTTP request body
RequestBody reqBody;
String contentType = headerParams.get("Content-Type");
String contentTypePure = contentType;
if (contentTypePure != null && contentTypePure.contains(";")) {
contentTypePure = contentType.substring(0, contentType.indexOf(";"));
}
if (!HttpMethod.permitsRequestBody(method)) {
reqBody = null;
} else if ("application/x-www-form-urlencoded".equals(contentType)) {
} else if ("application/x-www-form-urlencoded".equals(contentTypePure)) {
reqBody = buildRequestBodyFormEncoding(formParams);
} else if ("multipart/form-data".equals(contentType)) {
} else if ("multipart/form-data".equals(contentTypePure)) {
reqBody = buildRequestBodyMultipart(formParams);
} else if (body == null) {
if ("DELETE".equals(method)) {

View File

@ -1189,12 +1189,15 @@ public class ApiClient {
// prepare HTTP request body
RequestBody reqBody;
String contentType = headerParams.get("Content-Type");
String contentTypePure = contentType;
if (contentTypePure != null && contentTypePure.contains(";")) {
contentTypePure = contentType.substring(0, contentType.indexOf(";"));
}
if (!HttpMethod.permitsRequestBody(method)) {
reqBody = null;
} else if ("application/x-www-form-urlencoded".equals(contentType)) {
} else if ("application/x-www-form-urlencoded".equals(contentTypePure)) {
reqBody = buildRequestBodyFormEncoding(formParams);
} else if ("multipart/form-data".equals(contentType)) {
} else if ("multipart/form-data".equals(contentTypePure)) {
reqBody = buildRequestBodyMultipart(formParams);
} else if (body == null) {
if ("DELETE".equals(method)) {

View File

@ -1274,12 +1274,15 @@ public class ApiClient {
// prepare HTTP request body
RequestBody reqBody;
String contentType = headerParams.get("Content-Type");
String contentTypePure = contentType;
if (contentTypePure != null && contentTypePure.contains(";")) {
contentTypePure = contentType.substring(0, contentType.indexOf(";"));
}
if (!HttpMethod.permitsRequestBody(method)) {
reqBody = null;
} else if ("application/x-www-form-urlencoded".equals(contentType)) {
} else if ("application/x-www-form-urlencoded".equals(contentTypePure)) {
reqBody = buildRequestBodyFormEncoding(formParams);
} else if ("multipart/form-data".equals(contentType)) {
} else if ("multipart/form-data".equals(contentTypePure)) {
reqBody = buildRequestBodyMultipart(formParams);
} else if (body == null) {
if ("DELETE".equals(method)) {

View File

@ -1267,12 +1267,15 @@ public class ApiClient {
// prepare HTTP request body
RequestBody reqBody;
String contentType = headerParams.get("Content-Type");
String contentTypePure = contentType;
if (contentTypePure != null && contentTypePure.contains(";")) {
contentTypePure = contentType.substring(0, contentType.indexOf(";"));
}
if (!HttpMethod.permitsRequestBody(method)) {
reqBody = null;
} else if ("application/x-www-form-urlencoded".equals(contentType)) {
} else if ("application/x-www-form-urlencoded".equals(contentTypePure)) {
reqBody = buildRequestBodyFormEncoding(formParams);
} else if ("multipart/form-data".equals(contentType)) {
} else if ("multipart/form-data".equals(contentTypePure)) {
reqBody = buildRequestBodyMultipart(formParams);
} else if (body == null) {
if ("DELETE".equals(method)) {

View File

@ -1262,12 +1262,15 @@ public class ApiClient {
// prepare HTTP request body
RequestBody reqBody;
String contentType = headerParams.get("Content-Type");
String contentTypePure = contentType;
if (contentTypePure != null && contentTypePure.contains(";")) {
contentTypePure = contentType.substring(0, contentType.indexOf(";"));
}
if (!HttpMethod.permitsRequestBody(method)) {
reqBody = null;
} else if ("application/x-www-form-urlencoded".equals(contentType)) {
} else if ("application/x-www-form-urlencoded".equals(contentTypePure)) {
reqBody = buildRequestBodyFormEncoding(formParams);
} else if ("multipart/form-data".equals(contentType)) {
} else if ("multipart/form-data".equals(contentTypePure)) {
reqBody = buildRequestBodyMultipart(formParams);
} else if (body == null) {
if ("DELETE".equals(method)) {

View File

@ -1265,12 +1265,15 @@ public class ApiClient {
// prepare HTTP request body
RequestBody reqBody;
String contentType = headerParams.get("Content-Type");
String contentTypePure = contentType;
if (contentTypePure != null && contentTypePure.contains(";")) {
contentTypePure = contentType.substring(0, contentType.indexOf(";"));
}
if (!HttpMethod.permitsRequestBody(method)) {
reqBody = null;
} else if ("application/x-www-form-urlencoded".equals(contentType)) {
} else if ("application/x-www-form-urlencoded".equals(contentTypePure)) {
reqBody = buildRequestBodyFormEncoding(formParams);
} else if ("multipart/form-data".equals(contentType)) {
} else if ("multipart/form-data".equals(contentTypePure)) {
reqBody = buildRequestBodyMultipart(formParams);
} else if (body == null) {
if ("DELETE".equals(method)) {

View File

@ -1268,12 +1268,15 @@ public class ApiClient {
// prepare HTTP request body
RequestBody reqBody;
String contentType = headerParams.get("Content-Type");
String contentTypePure = contentType;
if (contentTypePure != null && contentTypePure.contains(";")) {
contentTypePure = contentType.substring(0, contentType.indexOf(";"));
}
if (!HttpMethod.permitsRequestBody(method)) {
reqBody = null;
} else if ("application/x-www-form-urlencoded".equals(contentType)) {
} else if ("application/x-www-form-urlencoded".equals(contentTypePure)) {
reqBody = buildRequestBodyFormEncoding(formParams);
} else if ("multipart/form-data".equals(contentType)) {
} else if ("multipart/form-data".equals(contentTypePure)) {
reqBody = buildRequestBodyMultipart(formParams);
} else if (body == null) {
if ("DELETE".equals(method)) {

View File

@ -1262,12 +1262,15 @@ public class ApiClient {
// prepare HTTP request body
RequestBody reqBody;
String contentType = headerParams.get("Content-Type");
String contentTypePure = contentType;
if (contentTypePure != null && contentTypePure.contains(";")) {
contentTypePure = contentType.substring(0, contentType.indexOf(";"));
}
if (!HttpMethod.permitsRequestBody(method)) {
reqBody = null;
} else if ("application/x-www-form-urlencoded".equals(contentType)) {
} else if ("application/x-www-form-urlencoded".equals(contentTypePure)) {
reqBody = buildRequestBodyFormEncoding(formParams);
} else if ("multipart/form-data".equals(contentType)) {
} else if ("multipart/form-data".equals(contentTypePure)) {
reqBody = buildRequestBodyMultipart(formParams);
} else if (body == null) {
if ("DELETE".equals(method)) {

View File

@ -1262,12 +1262,15 @@ public class ApiClient {
// prepare HTTP request body
RequestBody reqBody;
String contentType = headerParams.get("Content-Type");
String contentTypePure = contentType;
if (contentTypePure != null && contentTypePure.contains(";")) {
contentTypePure = contentType.substring(0, contentType.indexOf(";"));
}
if (!HttpMethod.permitsRequestBody(method)) {
reqBody = null;
} else if ("application/x-www-form-urlencoded".equals(contentType)) {
} else if ("application/x-www-form-urlencoded".equals(contentTypePure)) {
reqBody = buildRequestBodyFormEncoding(formParams);
} else if ("multipart/form-data".equals(contentType)) {
} else if ("multipart/form-data".equals(contentTypePure)) {
reqBody = buildRequestBodyMultipart(formParams);
} else if (body == null) {
if ("DELETE".equals(method)) {

View File

@ -1327,12 +1327,15 @@ public class ApiClient {
// prepare HTTP request body
RequestBody reqBody;
String contentType = headerParams.get("Content-Type");
String contentTypePure = contentType;
if (contentTypePure != null && contentTypePure.contains(";")) {
contentTypePure = contentType.substring(0, contentType.indexOf(";"));
}
if (!HttpMethod.permitsRequestBody(method)) {
reqBody = null;
} else if ("application/x-www-form-urlencoded".equals(contentType)) {
} else if ("application/x-www-form-urlencoded".equals(contentTypePure)) {
reqBody = buildRequestBodyFormEncoding(formParams);
} else if ("multipart/form-data".equals(contentType)) {
} else if ("multipart/form-data".equals(contentTypePure)) {
reqBody = buildRequestBodyMultipart(formParams);
} else if (body == null) {
if ("DELETE".equals(method)) {