Skip to content

Commit

Permalink
Fix #338 by supporting custom header in redirect()
Browse files Browse the repository at this point in the history
  • Loading branch information
seancorfield committed Jun 12, 2015
1 parent 184545a commit e9d25ce
Showing 1 changed file with 22 additions and 5 deletions.
27 changes: 22 additions & 5 deletions framework/one.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -966,7 +966,10 @@ component {
}

// call from your controller to redirect to a clean URL based on an action, pushing data to flash scope if necessary:
public void function redirect( string action, string preserve = 'none', string append = 'none', string path = variables.magicBaseURL, string queryString = '', string statusCode = '302' ) {
public void function redirect(
string action, string preserve = 'none', string append = 'none', string path = variables.magicBaseURL,
string queryString = '', string statusCode = '302', string header = ''
) {
if ( path == variables.magicBaseURL ) path = getBaseURL();
var preserveKey = '';
if ( preserve != 'none' ) {
Expand Down Expand Up @@ -1025,12 +1028,19 @@ component {
// ignore exception if session is not enabled
}
}
location( targetURL, false, statusCode );
if ( len( header ) ) {
// per #338 support custom header-based redirect
getPageContext().getResponse().setStatus( statusCode );
getPageContext().getResponse().setHeader( header, targetURL );
abortController();
} else {
location( targetURL, false, statusCode );
}
}

// append and querystring are not supported here: you are providing the URI so
// you are responsible for all of its contents
public void function redirectCustomURL( string uri, string preserve = 'none', string statusCode = '302' ) {
public void function redirectCustomURL( string uri, string preserve = 'none', string statusCode = '302', string header = '' ) {
var preserveKey = '';
if ( preserve != 'none' ) {
preserveKey = saveFlashContext( preserve );
Expand All @@ -1057,7 +1067,14 @@ component {
// ignore exception if session is not enabled
}
}
location( targetURL, false, statusCode );
if ( len( header ) ) {
// per #338 support custom header-based redirect
getPageContext().getResponse().setStatus( statusCode );
getPageContext().getResponse().setHeader( header, targetURL );
abortController();
} else {
location( targetURL, false, statusCode );
}
}

// call this to render data rather than a view and layouts
Expand Down Expand Up @@ -1900,7 +1917,7 @@ component {
break;
}
getPageContext().getResponse().setStatus( statusCode );
// set the content type header portably:
// Set the content type header portably:
getPageContext().getResponse().setContentType( contentType );
return out;
}
Expand Down

0 comments on commit e9d25ce

Please sign in to comment.