Skip to content

Commit

Permalink
Quote the multipart boundary header parameter value
Browse files Browse the repository at this point in the history
  • Loading branch information
chamil321 committed Feb 16, 2023
1 parent 914dc6d commit 164fb00
Showing 1 changed file with 14 additions and 4 deletions.
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

0 comments on commit 164fb00

Please sign in to comment.