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
pull/3/head
Tomasz Sowa 12 years ago
parent eaf10c70b7
commit ccc02f41bf

@ -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);

@ -131,6 +131,7 @@ private:
std::string url_to_fetch_on_exit;
std::string source_a;
std::string sendheadersstatic_t, sendheadersstatic_t2;
std::string sendfilea, sendfile2a;
void ProcessRequestThrow();
void ProcessRequest();
@ -157,6 +158,10 @@ private:
void FilterCompressSend(bool compressing, int compress_encoding, const std::wstring & source_ref);
void SendHeadersStatic();
void SendHeadersForbidden();
void SendHeadersRedirect();
void SendHeadersSendFile();
void SendHeadersCompression(int compress_encoding);
void SendHeadersNormal(Header header);
void SendHeaders(bool compressing, int compress_encoding, Header header);
int SelectDeflateVersion();
void SelectCompression(size_t source_len, bool & compression_allowed, int & compression_encoding);

@ -7,8 +7,8 @@
*
*/
#ifndef headerfileconfparser
#define headerfileconfparser
#ifndef headerfile_winix_core_confparser
#define headerfile_winix_core_confparser
#include <fstream>
#include <string>

@ -2,7 +2,7 @@
* This file is a part of Winix
* and is not publicly distributed
*
* Copyright (c) 2008-2010, Tomasz Sowa
* Copyright (c) 2008-2011, Tomasz Sowa
* All rights reserved.
*
*/
@ -77,6 +77,7 @@ void Request::Clear()
browser_msie = false;
redirect_to.clear();
redirect_type = 303;
x_sendfile.clear();
send_as_attachment = false;
}

@ -2,7 +2,7 @@
* This file is a part of Winix
* and is not publicly distributed
*
* Copyright (c) 2008-2010, Tomasz Sowa
* Copyright (c) 2008-2011, Tomasz Sowa
* All rights reserved.
*
*/
@ -102,6 +102,15 @@ struct Request
std::wstring redirect_to;
std::string aredirect_to;
// a redirect type
// following redirect types are supported:
// 300 Multiple Choices
// 301 Moved Permanently
// 302 Found
// 303 See Other (default)
// 307 Temporary Redirect
int redirect_type;
// send header X-LIGHTTPD-send-file with path to a file
std::wstring x_sendfile;

@ -20,6 +20,7 @@
#define WINIX_POSTTABLE_MAXSIZE 50
struct PostFile
{
std::wstring filename; // original file name

@ -72,6 +72,12 @@ public:
SLog & TranslateText(const char * str);
SLog & TranslateText(const wchar_t * str);
template<size_t str_size>
SLog & operator<<(const TranslateTextHelper<const char [str_size]> & raw) { return TranslateText(raw.par); }
template<size_t str_size>
SLog & operator<<(const TranslateTextHelper<const wchar_t [str_size]> & raw){ return TranslateText(raw.par); }
template<size_t str_size>
SLog & operator<<(const TranslateTextHelper<char [str_size]> & raw) { return TranslateText(raw.par); }

@ -424,11 +424,6 @@ return locale_files[lang];
}
size_t Locale::Size()
{
return loc_tab.size();
}
void Locale::UTF8(bool utf)
{

@ -64,9 +64,6 @@ public:
// how many languages we have
size_t Size();
// setting/getting current language
// default: 0
void SetLang(size_t lang);

Loading…
Cancel
Save