added: we can use different redirect codes now

(int Request::redirect_type variable)
       we can set following integer values:
       300 - Multiple Choices
       301 - Moved Permanently
       302 - Found
       307 - Temporary Redirect
       303 - See Other
       default is 303 for all redirects



git-svn-id: svn://ttmath.org/publicrep/winix/trunk@749 e52654a7-88a9-db11-a3e9-0013d4bc506e
This commit is contained in:
2011-07-07 17:02:14 +00:00
parent eaf10c70b7
commit ccc02f41bf
9 changed files with 106 additions and 48 deletions

View File

@@ -598,6 +598,82 @@ void App::SendHeadersForbidden()
}
void App::SendHeadersRedirect()
{
switch(cur.request->redirect_type)
{
case 300:
FCGX_PutS("Status: 300 Multiple Choices\r\n", fcgi_request.out);
break;
case 301:
FCGX_PutS("Status: 301 Moved Permanently\r\n", fcgi_request.out);
break;
case 302:
FCGX_PutS("Status: 302 Found\r\n", fcgi_request.out);
break;
case 307:
FCGX_PutS("Status: 307 Temporary Redirect\r\n", fcgi_request.out);
break;
case 303:
default:
FCGX_PutS("Status: 303 See Other\r\n", fcgi_request.out);
break;
}
UrlEncode(cur.request->redirect_to, cur.request->aredirect_to);
FCGX_FPrintF(fcgi_request.out, "Location: %s\r\n", cur.request->aredirect_to.c_str());
log << log2 << "Redirect to: " << cur.request->aredirect_to << logend;
}
void App::SendHeadersSendFile()
{
Ezc::WideToUTF8(config.http_header_send_file, sendfilea);
Ezc::WideToUTF8(cur.request->x_sendfile, sendfile2a);
FCGX_FPrintF(fcgi_request.out, "%s: %s\r\n", sendfilea.c_str(), sendfile2a.c_str());
FCGX_PutS("Status: 200 OK\r\n", fcgi_request.out);
log << log2 << "Sending file: " << cur.request->x_sendfile << logend;
}
void App::SendHeadersCompression(int compress_encoding)
{
if( compress_encoding == 0 || compress_encoding == 1 )
FCGX_PutS("Content-Encoding: deflate\r\n", fcgi_request.out);
else
FCGX_PutS("Content-Encoding: gzip\r\n", fcgi_request.out);
}
void App::SendHeadersNormal(Header header)
{
switch( header )
{
case h_404:
FCGX_PutS("Status: 404 Not Found\r\n", fcgi_request.out);
FCGX_PutS("Content-Type: text/html\r\n", fcgi_request.out);
log << log2 << "Request: response: 404 Not Found" << logend;
break;
case h_403:
SendHeadersForbidden();
break;
default:
FCGX_PutS("Status: 200 OK\r\n", fcgi_request.out);
if( cur.request->role != Request::authorizer )
FCGX_PutS("Content-Type: text/html\r\n", fcgi_request.out);
}
}
void App::SendHeaders(bool compressing, int compress_encoding, Header header)
{
PrepareSessionCookie();
@@ -607,10 +683,7 @@ void App::SendHeaders(bool compressing, int compress_encoding, Header header)
if( !cur.request->redirect_to.empty() )
{
FCGX_PutS("Status: 301 Moved Permanently\r\n", fcgi_request.out);
UrlEncode(cur.request->redirect_to, cur.request->aredirect_to);
FCGX_FPrintF(fcgi_request.out, "Location: %s\r\n", cur.request->aredirect_to.c_str());
log << log2 << "Redirect to: " << cur.request->aredirect_to << logend;
SendHeadersRedirect();
}
else
if( system.mounts.pmount->type == system.mounts.MountTypeStatic() )
@@ -620,44 +693,15 @@ void App::SendHeaders(bool compressing, int compress_encoding, Header header)
else
if( !cur.request->x_sendfile.empty() )
{
static std::string temp, temp2; // !! wrzucic gdzies to
Ezc::WideToUTF8(config.http_header_send_file, temp);
Ezc::WideToUTF8(cur.request->x_sendfile, temp2);
FCGX_FPrintF(fcgi_request.out, "%s: %s\r\n", temp.c_str(), temp2.c_str());
FCGX_PutS("Status: 200 OK\r\n", fcgi_request.out);
log << log2 << "Sending file: " << cur.request->x_sendfile << logend;
SendHeadersSendFile();
}
else
{
switch( header )
{
case h_404:
FCGX_PutS("Status: 404 Not Found\r\n", fcgi_request.out);
FCGX_PutS("Content-Type: text/html\r\n", fcgi_request.out);
log << log2 << "Request: response: 404 Not Found" << logend;
break;
case h_403:
SendHeadersForbidden();
break;
default:
FCGX_PutS("Status: 200 OK\r\n", fcgi_request.out);
if( cur.request->role != Request::authorizer )
FCGX_PutS("Content-Type: text/html\r\n", fcgi_request.out);
}
SendHeadersNormal(header);
}
if( compressing )
{
if( compress_encoding == 0 || compress_encoding == 1 )
FCGX_PutS("Content-Encoding: deflate\r\n", fcgi_request.out);
else
FCGX_PutS("Content-Encoding: gzip\r\n", fcgi_request.out);
}
SendHeadersCompression(compress_encoding);
FCGX_PutS(cur.request->headers.CStr(), fcgi_request.out);
FCGX_PutS("\r\n", fcgi_request.out);