mirror of
https://github.com/VCMP-SqMod/SqMod.git
synced 2024-11-08 00:37:15 +01:00
Update code for changes to CPR library.
This commit is contained in:
parent
f23a2fe389
commit
2a06a00e3e
@ -16,6 +16,7 @@ SQMOD_DECL_TYPENAME(SqCpResponse, _SC("SqCprResponse"))
|
|||||||
SQMOD_DECL_TYPENAME(SqCpParameters, _SC("SqCprParameters"))
|
SQMOD_DECL_TYPENAME(SqCpParameters, _SC("SqCprParameters"))
|
||||||
SQMOD_DECL_TYPENAME(SqCpPayload, _SC("SqCprPayload"))
|
SQMOD_DECL_TYPENAME(SqCpPayload, _SC("SqCprPayload"))
|
||||||
SQMOD_DECL_TYPENAME(SqCpProxies, _SC("SqCprProxies"))
|
SQMOD_DECL_TYPENAME(SqCpProxies, _SC("SqCprProxies"))
|
||||||
|
SQMOD_DECL_TYPENAME(SqCpRedirect, _SC("SqCprRedirect"))
|
||||||
SQMOD_DECL_TYPENAME(SqCpSession, _SC("SqCprSession"))
|
SQMOD_DECL_TYPENAME(SqCpSession, _SC("SqCprSession"))
|
||||||
|
|
||||||
/* ------------------------------------------------------------------------------------------------
|
/* ------------------------------------------------------------------------------------------------
|
||||||
@ -404,10 +405,20 @@ static const EnumElement g_StatusCodes[] = {
|
|||||||
{_SC("MISC_CODE_OFFSET"), cpr::status::MISC_CODE_OFFSET}
|
{_SC("MISC_CODE_OFFSET"), cpr::status::MISC_CODE_OFFSET}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// ------------------------------------------------------------------------------------------------
|
||||||
|
static const EnumElement g_PostRedirectFlags[] = {
|
||||||
|
{_SC("Post301"), static_cast< SQInteger >(cpr::PostRedirectFlags::POST_301)},
|
||||||
|
{_SC("Post302"), static_cast< SQInteger >(cpr::PostRedirectFlags::POST_302)},
|
||||||
|
{_SC("Post303"), static_cast< SQInteger >(cpr::PostRedirectFlags::POST_303)},
|
||||||
|
{_SC("Postall"), static_cast< SQInteger >(cpr::PostRedirectFlags::POST_ALL)},
|
||||||
|
{_SC("None"), static_cast< SQInteger >(cpr::PostRedirectFlags::NONE)},
|
||||||
|
};
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
static const EnumElements g_EnumList[] = {
|
static const EnumElements g_EnumList[] = {
|
||||||
{_SC("SqCprErrorCode"), g_ErrorCodes},
|
{_SC("SqCprErrorCode"), g_ErrorCodes},
|
||||||
{_SC("SqCprStatusCode"), g_StatusCodes}
|
{_SC("SqCprStatusCode"), g_StatusCodes},
|
||||||
|
{_SC("SqCprPostRedirectFlags"), g_PostRedirectFlags}
|
||||||
};
|
};
|
||||||
|
|
||||||
// ================================================================================================
|
// ================================================================================================
|
||||||
@ -605,6 +616,26 @@ void Register_CURL(HSQUIRRELVM vm)
|
|||||||
.CbFunc(_SC("While"), &CpProxies::While)
|
.CbFunc(_SC("While"), &CpProxies::While)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// --------------------------------------------------------------------------------------------
|
||||||
|
cpns.Bind(_SC("Redirect"),
|
||||||
|
Class< CpRedirect >(vm, SqCpRedirect::Str)
|
||||||
|
// Constructors
|
||||||
|
.Ctor()
|
||||||
|
.Ctor< SQInteger >()
|
||||||
|
.Ctor< SQInteger, bool >()
|
||||||
|
.Ctor< SQInteger, bool, SQInteger >()
|
||||||
|
// Meta-methods
|
||||||
|
.SquirrelFunc(_SC("_typename"), &SqCpRedirect::Fn)
|
||||||
|
// Properties
|
||||||
|
.Prop(_SC("Maximum"), &CpRedirect::GetMaximum, &CpRedirect::SetMaximum)
|
||||||
|
.Prop(_SC("Follow"), &CpRedirect::GetFollow, &CpRedirect::SetFollow)
|
||||||
|
.Prop(_SC("Flags"), &CpRedirect::GetFlags, &CpRedirect::SetFlags)
|
||||||
|
// Member Methods
|
||||||
|
.Func(_SC("SetMaximum"), &CpRedirect::ApplyMaximum)
|
||||||
|
.Func(_SC("SetFollow"), &CpRedirect::ApplyFollow)
|
||||||
|
.Func(_SC("SetFlags"), &CpRedirect::ApplyFlags)
|
||||||
|
);
|
||||||
|
|
||||||
// --------------------------------------------------------------------------------------------
|
// --------------------------------------------------------------------------------------------
|
||||||
cpns.Bind(_SC("Session"),
|
cpns.Bind(_SC("Session"),
|
||||||
Class< CpSession, NoCopy< CpSession > >(vm, SqCpSession::Str)
|
Class< CpSession, NoCopy< CpSession > >(vm, SqCpSession::Str)
|
||||||
@ -631,7 +662,6 @@ void Register_CURL(HSQUIRRELVM vm)
|
|||||||
.Func(_SC("YieldProxies"), &CpSession::YieldProxies)
|
.Func(_SC("YieldProxies"), &CpSession::YieldProxies)
|
||||||
.FmtFunc(_SC("SetNTLM"), &CpSession::SetNTLM_)
|
.FmtFunc(_SC("SetNTLM"), &CpSession::SetNTLM_)
|
||||||
.Func(_SC("SetRedirect"), &CpSession::SetRedirect_)
|
.Func(_SC("SetRedirect"), &CpSession::SetRedirect_)
|
||||||
.Func(_SC("SetMaxRedirects"), &CpSession::SetMaxRedirects_)
|
|
||||||
.Func(_SC("SetCookies"), &CpSession::SetCookies_)
|
.Func(_SC("SetCookies"), &CpSession::SetCookies_)
|
||||||
.FmtFunc(_SC("SetBody"), &CpSession::SetBody_)
|
.FmtFunc(_SC("SetBody"), &CpSession::SetBody_)
|
||||||
.Func(_SC("SetLowSpeed"), &CpSession::SetLowSpeed_)
|
.Func(_SC("SetLowSpeed"), &CpSession::SetLowSpeed_)
|
||||||
|
@ -888,7 +888,7 @@ struct CpResponse : public cpr::Response
|
|||||||
*/
|
*/
|
||||||
void SetStatusCode(SQInteger value)
|
void SetStatusCode(SQInteger value)
|
||||||
{
|
{
|
||||||
cpr::Response::status_code = value;
|
cpr::Response::status_code = static_cast< long >(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* --------------------------------------------------------------------------------------------
|
/* --------------------------------------------------------------------------------------------
|
||||||
@ -1604,6 +1604,152 @@ struct CpProxies : public cpr::Proxies
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/* ------------------------------------------------------------------------------------------------
|
||||||
|
* Wrapper for cpr::Redirect that can be bound to the script engine.
|
||||||
|
*/
|
||||||
|
struct CpRedirect : public cpr::Redirect
|
||||||
|
{
|
||||||
|
using cpr::Redirect::Redirect;
|
||||||
|
/* --------------------------------------------------------------------------------------------
|
||||||
|
* Default constructor.
|
||||||
|
*/
|
||||||
|
CpRedirect() = default;
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------
|
||||||
|
* Explicit constructor.
|
||||||
|
*/
|
||||||
|
explicit CpRedirect(SQInteger maximum)
|
||||||
|
: cpr::Redirect(static_cast< long >(maximum), true, cpr::PostRedirectFlags::POST_ALL)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------
|
||||||
|
* Explicit constructor.
|
||||||
|
*/
|
||||||
|
CpRedirect(SQInteger maximum, bool follow)
|
||||||
|
: cpr::Redirect(static_cast< long >(maximum), follow, cpr::PostRedirectFlags::POST_ALL)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------
|
||||||
|
* Explicit constructor.
|
||||||
|
*/
|
||||||
|
CpRedirect(SQInteger maximum, bool follow, SQInteger post_flags)
|
||||||
|
: cpr::Redirect(static_cast< long >(maximum), follow, static_cast< cpr::PostRedirectFlags >(post_flags))
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------
|
||||||
|
* Copy constructor.
|
||||||
|
*/
|
||||||
|
explicit CpRedirect(const cpr::Redirect & e) : cpr::Redirect(e) { }
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------
|
||||||
|
* Move constructor.
|
||||||
|
*/
|
||||||
|
explicit CpRedirect(cpr::Redirect && e) : cpr::Redirect(e) { }
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------
|
||||||
|
* Copy constructor.
|
||||||
|
*/
|
||||||
|
CpRedirect(const CpRedirect &) = default;
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------
|
||||||
|
* Move constructor.
|
||||||
|
*/
|
||||||
|
CpRedirect(CpRedirect &&) noexcept = default;
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------
|
||||||
|
* Destructor.
|
||||||
|
*/
|
||||||
|
~CpRedirect() = default;
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------
|
||||||
|
* Copy assignment operator.
|
||||||
|
*/
|
||||||
|
CpRedirect & operator = (const CpRedirect &) = default;
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------
|
||||||
|
* Move assignment operator.
|
||||||
|
*/
|
||||||
|
CpRedirect & operator = (CpRedirect &&) noexcept = default;
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------
|
||||||
|
* Retrieve the maximum number of redirects to follow. 0: Refuse any redirects. -1: Infinite number of redirects.
|
||||||
|
*/
|
||||||
|
SQMOD_NODISCARD SQInteger GetMaximum() const noexcept
|
||||||
|
{
|
||||||
|
return static_cast< SQInteger >(cpr::Redirect::maximum);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------
|
||||||
|
* Modify the maximum number of redirects to follow. 0: Refuse any redirects. -1: Infinite number of redirects.
|
||||||
|
*/
|
||||||
|
void SetMaximum(SQInteger value) noexcept
|
||||||
|
{
|
||||||
|
cpr::Redirect::maximum = static_cast< long >(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------
|
||||||
|
* Modify the maximum number of redirects to follow. 0: Refuse any redirects. -1: Infinite number of redirects.
|
||||||
|
*/
|
||||||
|
CpRedirect & ApplyMaximum(SQInteger value) noexcept
|
||||||
|
{
|
||||||
|
SetMaximum(value);
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------
|
||||||
|
* Retrieve whether to follow 3xx redirects.
|
||||||
|
*/
|
||||||
|
SQMOD_NODISCARD bool GetFollow() const noexcept
|
||||||
|
{
|
||||||
|
return cpr::Redirect::follow;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------
|
||||||
|
* Modify whether to follow 3xx redirects.
|
||||||
|
*/
|
||||||
|
void SetFollow(bool value) noexcept
|
||||||
|
{
|
||||||
|
cpr::Redirect::follow = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------
|
||||||
|
* Modify whether to follow 3xx redirects.
|
||||||
|
*/
|
||||||
|
CpRedirect & ApplyFollow(bool value) noexcept
|
||||||
|
{
|
||||||
|
SetMaximum(value);
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------
|
||||||
|
* Retrieve the flags to control how to act after a redirect for a post request.
|
||||||
|
*/
|
||||||
|
SQMOD_NODISCARD bool GetFlags() const noexcept
|
||||||
|
{
|
||||||
|
return cpr::Redirect::follow;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------
|
||||||
|
* Modify the flags to control how to act after a redirect for a post request.
|
||||||
|
*/
|
||||||
|
void SetFlags(bool value) noexcept
|
||||||
|
{
|
||||||
|
cpr::Redirect::follow = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------
|
||||||
|
* Modify the flags to control how to act after a redirect for a post request.
|
||||||
|
*/
|
||||||
|
CpRedirect & ApplyFlags(bool value) noexcept
|
||||||
|
{
|
||||||
|
SetMaximum(value);
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
/* ------------------------------------------------------------------------------------------------
|
/* ------------------------------------------------------------------------------------------------
|
||||||
* Wrapper for cpr::Session that can be bound to the script engine.
|
* Wrapper for cpr::Session that can be bound to the script engine.
|
||||||
*/
|
*/
|
||||||
@ -1620,7 +1766,7 @@ struct CpSession : public cpr::Session
|
|||||||
/* --------------------------------------------------------------------------------------------
|
/* --------------------------------------------------------------------------------------------
|
||||||
* URL constructor.
|
* URL constructor.
|
||||||
*/
|
*/
|
||||||
CpSession(StackStrF & url)
|
explicit CpSession(StackStrF & url)
|
||||||
: cpr::Session()
|
: cpr::Session()
|
||||||
{
|
{
|
||||||
cpr::Session::SetUrl(cpr::Url(url.mPtr, url.GetSize()));
|
cpr::Session::SetUrl(cpr::Url(url.mPtr, url.GetSize()));
|
||||||
@ -1654,7 +1800,7 @@ struct CpSession : public cpr::Session
|
|||||||
/* --------------------------------------------------------------------------------------------
|
/* --------------------------------------------------------------------------------------------
|
||||||
* Throw exception if the session is locked.
|
* Throw exception if the session is locked.
|
||||||
*/
|
*/
|
||||||
void LockCheck()
|
void LockCheck() const
|
||||||
{
|
{
|
||||||
if (mPending)
|
if (mPending)
|
||||||
{
|
{
|
||||||
@ -1827,23 +1973,13 @@ struct CpSession : public cpr::Session
|
|||||||
/* --------------------------------------------------------------------------------------------
|
/* --------------------------------------------------------------------------------------------
|
||||||
* Modify redirect option.
|
* Modify redirect option.
|
||||||
*/
|
*/
|
||||||
CpSession & SetRedirect_(bool redirect)
|
CpSession & SetRedirect_(CpRedirect & redirect)
|
||||||
{
|
{
|
||||||
LockCheck();
|
LockCheck();
|
||||||
cpr::Session::SetRedirect(redirect);
|
cpr::Session::SetRedirect(redirect);
|
||||||
return *this; // Allow chaining
|
return *this; // Allow chaining
|
||||||
}
|
}
|
||||||
|
|
||||||
/* --------------------------------------------------------------------------------------------
|
|
||||||
* Modify max-redirects option.
|
|
||||||
*/
|
|
||||||
CpSession & SetMaxRedirects_(SQInteger max_redirects)
|
|
||||||
{
|
|
||||||
LockCheck();
|
|
||||||
cpr::Session::SetMaxRedirects(cpr::MaxRedirects(static_cast< int32_t >(max_redirects)));
|
|
||||||
return *this; // Allow chaining
|
|
||||||
}
|
|
||||||
|
|
||||||
/* --------------------------------------------------------------------------------------------
|
/* --------------------------------------------------------------------------------------------
|
||||||
* Modify cookies option.
|
* Modify cookies option.
|
||||||
*/
|
*/
|
||||||
|
Loading…
Reference in New Issue
Block a user