Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Quote the multipart boundary header parameter value #39628

Merged
merged 1 commit into from
May 26, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions stdlib/http/src/main/java/org/ballerinalang/net/http/HttpUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@
import java.util.stream.Collectors;

import static io.netty.handler.codec.http.HttpHeaderNames.CACHE_CONTROL;
import static io.netty.handler.codec.http.HttpHeaderNames.CONTENT_TYPE;
import static org.ballerinalang.jvm.observability.ObservabilityConstants.CONFIG_CLIENT_HTTP_URL_DISABLED;
import static org.ballerinalang.jvm.observability.ObservabilityConstants.PROPERTY_HTTP_HOST;
import static org.ballerinalang.jvm.observability.ObservabilityConstants.PROPERTY_HTTP_PORT;
Expand Down Expand Up @@ -1100,11 +1101,20 @@ public static String getContentTypeFromTransportMessage(HttpCarbonMessage transp
* @return The boundary string that was extracted from header or the newly generated one
*/
public static String addBoundaryIfNotExist(HttpCarbonMessage transportMessage, String contentType) {
String boundaryString;
String boundaryValue = HeaderUtil.extractBoundaryParameter(contentType);
boundaryString = boundaryValue != null ? sanitizeBoundary(boundaryValue) :
HttpUtil.addBoundaryParameter(transportMessage, contentType);
return boundaryString;
if (boundaryValue != null) {
boundaryValue = sanitizeBoundary(boundaryValue);
boolean validateContentType = MimeUtil.isValidateContentType(contentType);
if (!validateContentType) {
String headerValue = HeaderUtil.getHeaderValue(contentType);
MapValue<String, String> paramMap = HeaderUtil.getParamMap(contentType);
paramMap.put(BOUNDARY, MimeUtil.includeQuotes(boundaryValue));
contentType = HeaderUtil.appendHeaderParams(new StringBuilder(headerValue).append(";"), paramMap);
transportMessage.setHeader(String.valueOf(CONTENT_TYPE), contentType);
}
return boundaryValue;
}
return HttpUtil.addBoundaryParameter(transportMessage, contentType);
}

/**
Expand Down
Loading