Skip to content

Commit

Permalink
Merge pull request #2130 from DinithHerath/master
Browse files Browse the repository at this point in the history
  • Loading branch information
DinithHerath authored Jan 19, 2024
2 parents 835e814 + 1aeede7 commit 13da848
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public static String getAllowedOrigins(String origin, Set<String> allowedOrigins
} else if (allowedOrigins.contains(origin)) {
return origin;
} else {
return null;
return "";
}
}

Expand Down Expand Up @@ -86,7 +86,7 @@ public static void handleCORSHeaders(CORSConfiguration corsConfiguration, Messag
transportHeaders.get(RESTConstants.CORS_HEADER_ORIGIN));

// If the request origin is not allowed, set the status code to 403
if (isOptionsRequest(synCtx) && allowedOrigin == null) {
if (isOptionsRequest(synCtx) && allowedOrigin.isEmpty()) {
((Axis2MessageContext) synCtx).getAxis2MessageContext()
.setProperty(PassThroughConstants.HTTP_SC, HttpStatus.SC_FORBIDDEN);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,34 +153,13 @@ public static SourceResponse create(MessageContext msgContext,
private static void addResponseHeader(SourceResponse sourceResponse, Map transportHeaders) {
for (Object entryObj : transportHeaders.entrySet()) {
Map.Entry entry = (Map.Entry) entryObj;
String headerValue = getHeaderValueAsString(entry.getValue());
if (entry.getKey() instanceof String && headerValue != null) {
sourceResponse.addHeader((String) entry.getKey(), headerValue);
}
if (entry.getValue() != null && entry.getKey() instanceof String &&
entry.getValue() instanceof String) {
sourceResponse.addHeader((String) entry.getKey(), (String) entry.getValue());
}
}
}

/**
* Get the header value as a string.
* <p>
* If the header value is a string, return it
* If the header value is null, return empty string. otherwise the header will get dropped
* Else return null to drop the header
* </p>
*
* @param value the header value
* @return the header value as a string
*/
private static String getHeaderValueAsString(Object value) {

if (value instanceof String) {
return (String) value;
} else if (value == null) {
return "";
}
return null;
}

private static boolean isPayloadOptionalMethod(String httpMethod) {
return (PassThroughConstants.HTTP_GET.equals(httpMethod) ||
PassThroughConstants.HTTP_HEAD.equals(httpMethod) ||
Expand Down

0 comments on commit 13da848

Please sign in to comment.