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:
parent
eaf10c70b7
commit
ccc02f41bf
116
core/app.cpp
116
core/app.cpp
|
@ -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)
|
void App::SendHeaders(bool compressing, int compress_encoding, Header header)
|
||||||
{
|
{
|
||||||
PrepareSessionCookie();
|
PrepareSessionCookie();
|
||||||
|
@ -607,10 +683,7 @@ void App::SendHeaders(bool compressing, int compress_encoding, Header header)
|
||||||
|
|
||||||
if( !cur.request->redirect_to.empty() )
|
if( !cur.request->redirect_to.empty() )
|
||||||
{
|
{
|
||||||
FCGX_PutS("Status: 301 Moved Permanently\r\n", fcgi_request.out);
|
SendHeadersRedirect();
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
if( system.mounts.pmount->type == system.mounts.MountTypeStatic() )
|
if( system.mounts.pmount->type == system.mounts.MountTypeStatic() )
|
||||||
|
@ -620,44 +693,15 @@ void App::SendHeaders(bool compressing, int compress_encoding, Header header)
|
||||||
else
|
else
|
||||||
if( !cur.request->x_sendfile.empty() )
|
if( !cur.request->x_sendfile.empty() )
|
||||||
{
|
{
|
||||||
static std::string temp, temp2; // !! wrzucic gdzies to
|
SendHeadersSendFile();
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
switch( header )
|
SendHeadersNormal(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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if( compressing )
|
if( compressing )
|
||||||
{
|
SendHeadersCompression(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);
|
|
||||||
}
|
|
||||||
|
|
||||||
FCGX_PutS(cur.request->headers.CStr(), fcgi_request.out);
|
FCGX_PutS(cur.request->headers.CStr(), fcgi_request.out);
|
||||||
FCGX_PutS("\r\n", fcgi_request.out);
|
FCGX_PutS("\r\n", fcgi_request.out);
|
||||||
|
|
|
@ -131,6 +131,7 @@ private:
|
||||||
std::string url_to_fetch_on_exit;
|
std::string url_to_fetch_on_exit;
|
||||||
std::string source_a;
|
std::string source_a;
|
||||||
std::string sendheadersstatic_t, sendheadersstatic_t2;
|
std::string sendheadersstatic_t, sendheadersstatic_t2;
|
||||||
|
std::string sendfilea, sendfile2a;
|
||||||
|
|
||||||
void ProcessRequestThrow();
|
void ProcessRequestThrow();
|
||||||
void ProcessRequest();
|
void ProcessRequest();
|
||||||
|
@ -157,6 +158,10 @@ private:
|
||||||
void FilterCompressSend(bool compressing, int compress_encoding, const std::wstring & source_ref);
|
void FilterCompressSend(bool compressing, int compress_encoding, const std::wstring & source_ref);
|
||||||
void SendHeadersStatic();
|
void SendHeadersStatic();
|
||||||
void SendHeadersForbidden();
|
void SendHeadersForbidden();
|
||||||
|
void SendHeadersRedirect();
|
||||||
|
void SendHeadersSendFile();
|
||||||
|
void SendHeadersCompression(int compress_encoding);
|
||||||
|
void SendHeadersNormal(Header header);
|
||||||
void SendHeaders(bool compressing, int compress_encoding, Header header);
|
void SendHeaders(bool compressing, int compress_encoding, Header header);
|
||||||
int SelectDeflateVersion();
|
int SelectDeflateVersion();
|
||||||
void SelectCompression(size_t source_len, bool & compression_allowed, int & compression_encoding);
|
void SelectCompression(size_t source_len, bool & compression_allowed, int & compression_encoding);
|
||||||
|
|
|
@ -7,8 +7,8 @@
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef headerfileconfparser
|
#ifndef headerfile_winix_core_confparser
|
||||||
#define headerfileconfparser
|
#define headerfile_winix_core_confparser
|
||||||
|
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
* This file is a part of Winix
|
* This file is a part of Winix
|
||||||
* and is not publicly distributed
|
* and is not publicly distributed
|
||||||
*
|
*
|
||||||
* Copyright (c) 2008-2010, Tomasz Sowa
|
* Copyright (c) 2008-2011, Tomasz Sowa
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
@ -77,6 +77,7 @@ void Request::Clear()
|
||||||
|
|
||||||
browser_msie = false;
|
browser_msie = false;
|
||||||
redirect_to.clear();
|
redirect_to.clear();
|
||||||
|
redirect_type = 303;
|
||||||
x_sendfile.clear();
|
x_sendfile.clear();
|
||||||
send_as_attachment = false;
|
send_as_attachment = false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
* This file is a part of Winix
|
* This file is a part of Winix
|
||||||
* and is not publicly distributed
|
* and is not publicly distributed
|
||||||
*
|
*
|
||||||
* Copyright (c) 2008-2010, Tomasz Sowa
|
* Copyright (c) 2008-2011, Tomasz Sowa
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
@ -102,6 +102,15 @@ struct Request
|
||||||
std::wstring redirect_to;
|
std::wstring redirect_to;
|
||||||
std::string aredirect_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
|
// send header X-LIGHTTPD-send-file with path to a file
|
||||||
std::wstring x_sendfile;
|
std::wstring x_sendfile;
|
||||||
|
|
||||||
|
|
|
@ -20,6 +20,7 @@
|
||||||
#define WINIX_POSTTABLE_MAXSIZE 50
|
#define WINIX_POSTTABLE_MAXSIZE 50
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
struct PostFile
|
struct PostFile
|
||||||
{
|
{
|
||||||
std::wstring filename; // original file name
|
std::wstring filename; // original file name
|
||||||
|
|
|
@ -72,6 +72,12 @@ public:
|
||||||
SLog & TranslateText(const char * str);
|
SLog & TranslateText(const char * str);
|
||||||
SLog & TranslateText(const wchar_t * 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>
|
template<size_t str_size>
|
||||||
SLog & operator<<(const TranslateTextHelper<char [str_size]> & raw) { return TranslateText(raw.par); }
|
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)
|
void Locale::UTF8(bool utf)
|
||||||
{
|
{
|
||||||
|
|
|
@ -64,9 +64,6 @@ public:
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// how many languages we have
|
|
||||||
size_t Size();
|
|
||||||
|
|
||||||
// setting/getting current language
|
// setting/getting current language
|
||||||
// default: 0
|
// default: 0
|
||||||
void SetLang(size_t lang);
|
void SetLang(size_t lang);
|
||||||
|
|
Loading…
Reference in New Issue