Skip to content

Commit

Permalink
Updates after review.
Browse files Browse the repository at this point in the history
Signed-off-by: Simone Bordet <simone.bordet@gmail.com>
  • Loading branch information
sbordet committed Jan 10, 2024
1 parent b2a0ded commit d735933
Showing 1 changed file with 10 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ public class CrossOriginHandler extends Handler.Wrapper
private final Set<Pattern> allowedTimingOriginPatterns = new LinkedHashSet<>();
private PreEncodedHttpField accessControlAllowMethodsField;
private PreEncodedHttpField accessControlAllowHeadersField;
private PreEncodedHttpField accessControlExposeHeadersField;
private PreEncodedHttpField accessControlMaxAge;

/**
Expand Down Expand Up @@ -101,7 +102,7 @@ public void setAllowCredentials(boolean allow)
}

/**
* @return the set of allowed headers in a cross-origin request
* @return the immutable set of allowed headers in a cross-origin request
*/
@ManagedAttribute("The set of allowed headers in a cross-origin request")
public Set<String> getAllowedHeaders()
Expand All @@ -128,7 +129,7 @@ public void setAllowedHeaders(Set<String> headers)
}

/**
* @return the set of allowed methods in a cross-origin request
* @return the immutable set of allowed methods in a cross-origin request
*/
@ManagedAttribute("The set of allowed methods in a cross-origin request")
public Set<String> getAllowedMethods()
Expand All @@ -153,7 +154,7 @@ public void setAllowedMethods(Set<String> methods)
}

/**
* @return the set of allowed origin regex strings in a cross-origin request
* @return the immutable set of allowed origin regex strings in a cross-origin request
*/
@ManagedAttribute("The set of allowed origin regex strings in a cross-origin request")
public Set<String> getAllowedOriginPatterns()
Expand Down Expand Up @@ -184,7 +185,7 @@ public void setAllowedOriginPatterns(Set<String> origins)
}

/**
* @return the set of allowed timing origin regex strings in a cross-origin request
* @return the immutable set of allowed timing origin regex strings in a cross-origin request
*/
@ManagedAttribute("The set of allowed timing origin regex strings in a cross-origin request")
public Set<String> getAllowedTimingOriginPatterns()
Expand Down Expand Up @@ -265,7 +266,7 @@ public void setDeliverNonAllowedOriginWebSocketUpgradeRequests(boolean deliverNo
}

/**
* @return the set of headers exposed in a cross-origin response
* @return the immutable set of headers exposed in a cross-origin response
*/
@ManagedAttribute("The set of headers exposed in a cross-origin response")
public Set<String> getExposedHeaders()
Expand Down Expand Up @@ -311,6 +312,7 @@ protected void doStart() throws Exception
resolveAllowedTimingOrigins();
accessControlAllowMethodsField = new PreEncodedHttpField(HttpHeader.ACCESS_CONTROL_ALLOW_METHODS, String.join(",", getAllowedMethods()));
accessControlAllowHeadersField = new PreEncodedHttpField(HttpHeader.ACCESS_CONTROL_ALLOW_HEADERS, String.join(",", getAllowedHeaders()));
accessControlExposeHeadersField = new PreEncodedHttpField(HttpHeader.ACCESS_CONTROL_EXPOSE_HEADERS, String.join(",", getExposedHeaders()));
accessControlMaxAge = new PreEncodedHttpField(HttpHeader.ACCESS_CONTROL_MAX_AGE, getPreflightMaxAge().toSeconds());
super.doStart();
}
Expand Down Expand Up @@ -475,7 +477,7 @@ private void handleSimpleResponse(String origin, Response response)
headers.put(ACCESS_CONTROL_ALLOW_CREDENTIALS_TRUE);
Set<String> exposedHeaders = getExposedHeaders();
if (!exposedHeaders.isEmpty())
headers.put(HttpHeader.ACCESS_CONTROL_EXPOSE_HEADERS, String.join(",", exposedHeaders));
headers.put(accessControlExposeHeadersField);
}

private void resolveAllowedOrigins()
Expand All @@ -492,7 +494,7 @@ private void resolveAllowedOrigins()
return;
}

allowedOriginPatterns.add(Pattern.compile(allowedOrigin));
allowedOriginPatterns.add(Pattern.compile(allowedOrigin, Pattern.CASE_INSENSITIVE));
}
}

Expand All @@ -510,7 +512,7 @@ private void resolveAllowedTimingOrigins()
return;
}

allowedTimingOriginPatterns.add(Pattern.compile(allowedTimingOrigin));
allowedTimingOriginPatterns.add(Pattern.compile(allowedTimingOrigin, Pattern.CASE_INSENSITIVE));
}
}

Expand Down

0 comments on commit d735933

Please sign in to comment.