* @throws RedirectException a special exception to be intercepted by Micro so it can
* halt the current process and return the control back to the JRack
*/
public void setRedirect(String path, boolean secure, int redirectCode) throws RedirectException {
if (path != null && !path.isEmpty()) {
RackResponse response = getRackResponse();
String method = getRequest() != null? getRequest().getMethod(): Globals.EMPTY_STRING;
int rCode = redirectCode != 0 ? redirectCode :
(!"GET".equalsIgnoreCase(method) ? 303 : 302);
response = null;
response = new RackResponse(rCode)
.withBody(Globals.EMPTY_STRING)
.withContentLength(0);
int defaultPort = getRequest() != null? getRequest().getServerPort() : 8080;
UrlUtilities urlUtilities = new UrlUtilities(getRequest(), getResponse());
String location = secure ?
urlUtilities.buildSecure(path) :
urlUtilities.buildStandard(path, defaultPort);
with(Globals.RACK_RESPONSE, response.withHeader("Location", location));
throw new RedirectException();
}
}