move some methods from App to Request
methods moved: SetEnv(), ReadEnvVariables(), ReadEnvRemoteIP(), CheckSSL(), SetSubdomain() while here: - add the rest of http methods: put, connect, trace, patch
This commit is contained in:
@@ -143,13 +143,23 @@ bool FunctionBase::HasAccess()
|
||||
|
||||
|
||||
|
||||
void FunctionBase::MakeGet()
|
||||
{
|
||||
// do nothing by default
|
||||
}
|
||||
|
||||
void FunctionBase::MakeHead()
|
||||
{
|
||||
// by default call MakeGet() but do not return any content at the end of the request
|
||||
MakeGet();
|
||||
}
|
||||
|
||||
void FunctionBase::MakePost()
|
||||
{
|
||||
// do nothing by default
|
||||
}
|
||||
|
||||
|
||||
void FunctionBase::MakeGet()
|
||||
void FunctionBase::MakePut()
|
||||
{
|
||||
// do nothing by default
|
||||
}
|
||||
@@ -159,6 +169,10 @@ void FunctionBase::MakeDelete()
|
||||
// do nothing by default
|
||||
}
|
||||
|
||||
void FunctionBase::MakeConnect()
|
||||
{
|
||||
// do nothing by default
|
||||
}
|
||||
|
||||
void FunctionBase::MakeOptions()
|
||||
{
|
||||
@@ -166,6 +180,16 @@ void FunctionBase::MakeOptions()
|
||||
cur->request->out_headers.add(Header::allow, L"OPTIONS, GET, HEAD, POST, DELETE");
|
||||
}
|
||||
|
||||
void FunctionBase::MakeTrace()
|
||||
{
|
||||
// do nothing by default
|
||||
}
|
||||
|
||||
void FunctionBase::MakePatch()
|
||||
{
|
||||
// do nothing by default
|
||||
}
|
||||
|
||||
|
||||
void FunctionBase::Clear()
|
||||
{
|
||||
@@ -174,13 +198,22 @@ void FunctionBase::Clear()
|
||||
|
||||
|
||||
|
||||
void FunctionBase::ContinueMakeGet()
|
||||
{
|
||||
// do nothing by default
|
||||
}
|
||||
|
||||
void FunctionBase::ContinueMakeHead()
|
||||
{
|
||||
// do nothing by default
|
||||
}
|
||||
|
||||
void FunctionBase::ContinueMakePost()
|
||||
{
|
||||
// do nothing by default
|
||||
}
|
||||
|
||||
|
||||
void FunctionBase::ContinueMakeGet()
|
||||
void FunctionBase::ContinueMakePut()
|
||||
{
|
||||
// do nothing by default
|
||||
}
|
||||
@@ -190,11 +223,26 @@ void FunctionBase::ContinueMakeDelete()
|
||||
// do nothing by default
|
||||
}
|
||||
|
||||
void FunctionBase::ContinueMakeConnect()
|
||||
{
|
||||
// do nothing by default
|
||||
}
|
||||
|
||||
void FunctionBase::ContinueMakeOptions()
|
||||
{
|
||||
// do nothing by default
|
||||
}
|
||||
|
||||
void FunctionBase::ContinueMakeTrace()
|
||||
{
|
||||
// do nothing by default
|
||||
}
|
||||
|
||||
void FunctionBase::ContinueMakePatch()
|
||||
{
|
||||
// do nothing by default
|
||||
}
|
||||
|
||||
|
||||
} // namespace Winix
|
||||
|
||||
|
@@ -110,20 +110,32 @@ public:
|
||||
virtual void Finish();
|
||||
|
||||
virtual bool HasAccess();
|
||||
virtual void MakePost();
|
||||
|
||||
virtual void MakeGet();
|
||||
virtual void MakeHead();
|
||||
virtual void MakePost();
|
||||
virtual void MakePut();
|
||||
virtual void MakeDelete();
|
||||
virtual void MakeConnect();
|
||||
virtual void MakeOptions();
|
||||
virtual void MakeTrace();
|
||||
virtual void MakePatch();
|
||||
|
||||
virtual void Clear();
|
||||
|
||||
/*
|
||||
* called from the jobs thread
|
||||
* objects are locked
|
||||
*/
|
||||
virtual void ContinueMakePost();
|
||||
virtual void ContinueMakeGet();
|
||||
virtual void ContinueMakeHead();
|
||||
virtual void ContinueMakePost();
|
||||
virtual void ContinueMakePut();
|
||||
virtual void ContinueMakeDelete();
|
||||
virtual void ContinueMakeConnect();
|
||||
virtual void ContinueMakeOptions();
|
||||
virtual void ContinueMakeTrace();
|
||||
virtual void ContinueMakePatch();
|
||||
|
||||
|
||||
//void SetConfig(Config * pconfig);
|
||||
|
@@ -462,57 +462,72 @@ void Functions::MakeFunction()
|
||||
{
|
||||
if( !cur->request->function )
|
||||
{
|
||||
cur->request->status = WINIX_ERR_NO_FUNCTION;
|
||||
log << log1 << "Functions: no function (neither cat nor ls)" << logend;
|
||||
cur->request->http_status = Header::status_500_internal_server_error; // or 404? (404 was originally)
|
||||
log << log1 << "Functions: no function to call" << logend;
|
||||
return;
|
||||
}
|
||||
|
||||
if( !system->DirsHaveReadExecPerm() ||
|
||||
!system->HasReadExecAccess(cur->request->function->fun) ||
|
||||
if( !system->DirsHaveReadExecPerm() ||
|
||||
!system->HasReadExecAccess(cur->request->function->fun) ||
|
||||
!cur->request->function->HasAccess() )
|
||||
{
|
||||
cur->request->status = WINIX_ERR_PERMISSION_DENIED;
|
||||
cur->request->http_status = Header::status_403_forbidden;
|
||||
return;
|
||||
}
|
||||
|
||||
if( !cur->request->redirect_to.empty() )
|
||||
{
|
||||
log << log3 << "Functions: there is a redirect_to set so I do not call the function" << logend;
|
||||
return;
|
||||
}
|
||||
|
||||
if( cur->request->method == Request::get )
|
||||
{
|
||||
if( cur->request->redirect_to.empty() )
|
||||
cur->request->function->MakeGet();
|
||||
}
|
||||
else
|
||||
if( cur->request->method == Request::post )
|
||||
{
|
||||
// we don't use post with redirecting (the post variables would be lost)
|
||||
|
||||
if( cur->request->redirect_to.empty() )
|
||||
cur->request->function->MakePost();
|
||||
else
|
||||
cur->request->status = WINIX_ERR_PERMISSION_DENIED;
|
||||
cur->request->function->MakeGet();
|
||||
}
|
||||
else
|
||||
if( cur->request->method == Request::head )
|
||||
{
|
||||
// do nothing
|
||||
|
||||
// !! IMPROVE ME
|
||||
// we should make a page similar like in a GET request but the content should not be returned only
|
||||
cur->request->function->MakeHead();
|
||||
}
|
||||
else
|
||||
if( cur->request->method == Request::post )
|
||||
{
|
||||
cur->request->function->MakePost();
|
||||
}
|
||||
else
|
||||
if( cur->request->method == Request::put )
|
||||
{
|
||||
cur->request->function->MakePut();
|
||||
}
|
||||
else
|
||||
if( cur->request->method == Request::delete_ )
|
||||
{
|
||||
if( cur->request->redirect_to.empty() )
|
||||
cur->request->function->MakeDelete();
|
||||
cur->request->function->MakeDelete();
|
||||
}
|
||||
else
|
||||
if( cur->request->method == Request::connect )
|
||||
{
|
||||
cur->request->function->MakeConnect();
|
||||
}
|
||||
else
|
||||
if( cur->request->method == Request::options )
|
||||
{
|
||||
if( cur->request->redirect_to.empty() )
|
||||
cur->request->function->MakeOptions();
|
||||
cur->request->function->MakeOptions();
|
||||
}
|
||||
else
|
||||
if( cur->request->method == Request::trace )
|
||||
{
|
||||
cur->request->function->MakeTrace();
|
||||
}
|
||||
else
|
||||
if( cur->request->method == Request::patch )
|
||||
{
|
||||
cur->request->function->MakePatch();
|
||||
}
|
||||
else
|
||||
{
|
||||
log << log1 << "Functions: unknown request method (skipping)" << logend;
|
||||
log << log1 << "Functions: I cannot call a function, an unknown request method (skipping)" << logend;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -521,57 +536,70 @@ void Functions::ContinueMakeFunction()
|
||||
{
|
||||
if( !cur->request->function )
|
||||
{
|
||||
cur->request->status = WINIX_ERR_NO_FUNCTION;
|
||||
log << log1 << "Functions: no function (neither cat nor ls)" << logend;
|
||||
cur->request->http_status = Header::status_500_internal_server_error; // or 404? (404 was originally)
|
||||
log << log1 << "Functions: no function to call in the request continuation" << logend;
|
||||
return;
|
||||
}
|
||||
|
||||
// if( !system->DirsHaveReadExecPerm() ||
|
||||
// !system->HasReadExecAccess(cur->request->function->fun) ||
|
||||
// !cur->request->function->HasAccess() )
|
||||
// {
|
||||
// cur->request->status = WINIX_ERR_PERMISSION_DENIED;
|
||||
// return;
|
||||
// }
|
||||
if( !system->DirsHaveReadExecPerm() ||
|
||||
!system->HasReadExecAccess(cur->request->function->fun) ||
|
||||
!cur->request->function->HasAccess() )
|
||||
{
|
||||
cur->request->http_status = Header::status_403_forbidden;
|
||||
return;
|
||||
}
|
||||
|
||||
log << log4 << "Functions: continuing method ";
|
||||
cur->request->PutMethodName(log);
|
||||
log << " for request " << cur->request << " for function " << cur->request->function->fun.url << logend;
|
||||
|
||||
if( cur->request->method == Request::get )
|
||||
{
|
||||
log << log4 << "Functions: continuing method get for request " << cur->request
|
||||
<< " for function " << cur->request->function->fun.url << logend;
|
||||
cur->request->function->ContinueMakeGet();
|
||||
}
|
||||
else
|
||||
if( cur->request->method == Request::post )
|
||||
{
|
||||
log << log4 << "Functions: continuing method post for request " << cur->request
|
||||
<< " for function " << cur->request->function->fun.url << logend;
|
||||
cur->request->function->ContinueMakePost();
|
||||
}
|
||||
else
|
||||
if( cur->request->method == Request::head )
|
||||
{
|
||||
// do nothing
|
||||
|
||||
// !! IMPROVE ME
|
||||
// we should make a page similar like in a GET request but the content should not be returned only
|
||||
cur->request->function->ContinueMakeHead();
|
||||
}
|
||||
else
|
||||
if( cur->request->method == Request::post )
|
||||
{
|
||||
cur->request->function->ContinueMakePost();
|
||||
}
|
||||
else
|
||||
if( cur->request->method == Request::put )
|
||||
{
|
||||
cur->request->function->ContinueMakePut();
|
||||
}
|
||||
else
|
||||
if( cur->request->method == Request::delete_ )
|
||||
{
|
||||
log << log4 << "Functions: continuing method delete for request " << cur->request
|
||||
<< " for function " << cur->request->function->fun.url << logend;
|
||||
cur->request->function->ContinueMakeDelete();
|
||||
}
|
||||
else
|
||||
if( cur->request->method == Request::connect )
|
||||
{
|
||||
cur->request->function->ContinueMakeConnect();
|
||||
}
|
||||
else
|
||||
if( cur->request->method == Request::options )
|
||||
{
|
||||
log << log4 << "Functions: continuing method options for request " << cur->request
|
||||
<< " for function " << cur->request->function->fun.url << logend;
|
||||
cur->request->function->ContinueMakeOptions();
|
||||
}
|
||||
else
|
||||
if( cur->request->method == Request::trace )
|
||||
{
|
||||
log << log1 << "Functions: cannot continue a request, unknown request method (skipping)" << logend;
|
||||
cur->request->function->ContinueMakeTrace();
|
||||
}
|
||||
else
|
||||
if( cur->request->method == Request::patch )
|
||||
{
|
||||
cur->request->function->ContinueMakePatch();
|
||||
}
|
||||
else
|
||||
{
|
||||
log << log1 << "Functions: I cannot continue a request, an unknown request method (skipping)" << logend;
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user