Added URL member to the HTTPRequest API class.
This commit is contained in:
parent
be4ac22b52
commit
de27f66b59
@ -2171,15 +2171,6 @@ local CompressedString = cStringCompression.CompressStringGZIP("DataToCompress")
|
||||
Inherits = "cEntity",
|
||||
},
|
||||
|
||||
cWebAdmin =
|
||||
{
|
||||
Desc = "",
|
||||
Functions =
|
||||
{
|
||||
GetHTMLEscapedString = { Params = "string", Return = "string", Notes = "Gets the HTML escaped representation of a requested string. This is useful for user input and game data that is not guaranteed to be escaped already." },
|
||||
},
|
||||
}, -- cWebAdmin
|
||||
|
||||
cWebPlugin =
|
||||
{
|
||||
Desc = "",
|
||||
@ -2502,39 +2493,6 @@ World:ForEachEntity(
|
||||
}, -- AdditionalInfo
|
||||
}, -- cWorld
|
||||
|
||||
HTTPFormData =
|
||||
{
|
||||
Desc = "This class stores data for one form element for a {{HTTPRequest|HTTP request}}.",
|
||||
Variables =
|
||||
{
|
||||
Name = { Type = "string", Notes = "Name of the form element" },
|
||||
Type = { Type = "string", Notes = "Type of the data (usually empty)" },
|
||||
Value = { Type = "string", Notes = "Value of the form element. Contains the raw data as sent by the browser." },
|
||||
},
|
||||
}, -- HTTPFormData
|
||||
|
||||
HTTPRequest =
|
||||
{
|
||||
Desc = [[
|
||||
This class encapsulates all the data that is sent to the WebAdmin through one HTTP request. Plugins
|
||||
receive this class as a parameter to the function handling the web requests, as registered in the
|
||||
FIXME: {{cPluginLua}}:AddWebPage().
|
||||
]],
|
||||
Constants =
|
||||
{
|
||||
FormData = { Notes = "Array-table of {{HTTPFormData}}, contains the values of individual form elements submitted by the client" },
|
||||
Params = { Notes = "Map-table of parameters given to the request in the URL (?param=value); if a form uses GET method, this is the same as FormData. For each parameter given as \"param=value\", there is an entry in the table with \"param\" as its key and \"value\" as its value." },
|
||||
PostParams = { Notes = "Map-table of data posted through a FORM - either a GET or POST method. Logically the same as FormData, but in a map-table format (for each parameter given as \"param=value\", there is an entry in the table with \"param\" as its key and \"value\" as its value)." },
|
||||
},
|
||||
|
||||
Variables =
|
||||
{
|
||||
Method = { Type = "string", Notes = "The HTTP method used to make the request. Usually GET or POST." },
|
||||
Path = { Type = "string", Notes = "The Path part of the URL (excluding the parameters)" },
|
||||
Username = { Type = "string", Notes = "Name of the logged-in user." },
|
||||
},
|
||||
}, -- HTTPRequest
|
||||
|
||||
ItemCategory =
|
||||
{
|
||||
Desc = [[
|
||||
|
51
MCServer/Plugins/APIDump/Classes/WebAdmin.lua
Normal file
51
MCServer/Plugins/APIDump/Classes/WebAdmin.lua
Normal file
@ -0,0 +1,51 @@
|
||||
return
|
||||
{
|
||||
cWebAdmin =
|
||||
{
|
||||
Desc = "",
|
||||
Functions =
|
||||
{
|
||||
GetHTMLEscapedString = { Params = "string", Return = "string", Notes = "(STATIC) Gets the HTML-escaped representation of a requested string. This is useful for user input and game data that is not guaranteed to be escaped already." },
|
||||
},
|
||||
}, -- cWebAdmin
|
||||
|
||||
|
||||
HTTPFormData =
|
||||
{
|
||||
Desc = "This class stores data for one form element for a {{HTTPRequest|HTTP request}}.",
|
||||
Variables =
|
||||
{
|
||||
Name = { Type = "string", Notes = "Name of the form element" },
|
||||
Type = { Type = "string", Notes = "Type of the data (usually empty)" },
|
||||
Value = { Type = "string", Notes = "Value of the form element. Contains the raw data as sent by the browser." },
|
||||
},
|
||||
}, -- HTTPFormData
|
||||
|
||||
|
||||
HTTPRequest =
|
||||
{
|
||||
Desc = [[
|
||||
This class encapsulates all the data that is sent to the WebAdmin through one HTTP request. Plugins
|
||||
receive this class as a parameter to the function handling the web requests, as registered in the
|
||||
{{cPluginLua}}:AddWebPage().
|
||||
]],
|
||||
Constants =
|
||||
{
|
||||
FormData = { Notes = "Array-table of {{HTTPFormData}}, contains the values of individual form elements submitted by the client" },
|
||||
Params = { Notes = "Map-table of parameters given to the request in the URL (?param=value); if a form uses GET method, this is the same as FormData. For each parameter given as \"param=value\", there is an entry in the table with \"param\" as its key and \"value\" as its value." },
|
||||
PostParams = { Notes = "Map-table of data posted through a FORM - either a GET or POST method. Logically the same as FormData, but in a map-table format (for each parameter given as \"param=value\", there is an entry in the table with \"param\" as its key and \"value\" as its value)." },
|
||||
},
|
||||
|
||||
Variables =
|
||||
{
|
||||
Method = { Type = "string", Notes = "The HTTP method used to make the request. Usually GET or POST." },
|
||||
Path = { Type = "string", Notes = "The Path part of the URL (excluding the parameters)" },
|
||||
URL = { Type = "string", Notes = "The entire URL used for the request." },
|
||||
Username = { Type = "string", Notes = "Name of the logged-in user." },
|
||||
},
|
||||
}, -- HTTPRequest
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
@ -234,7 +234,7 @@ void cWebAdmin::HandleWebadminRequest(cHTTPConnection & a_Connection, cHTTPReque
|
||||
bool ShouldWrapInTemplate = ((BareURL.length() > 1) && (BareURL[1] != '~'));
|
||||
|
||||
// Retrieve the request data:
|
||||
cWebadminRequestData * Data = (cWebadminRequestData *)(a_Request.GetUserData());
|
||||
cWebadminRequestData * Data = reinterpret_cast<cWebadminRequestData *>(a_Request.GetUserData());
|
||||
if (Data == nullptr)
|
||||
{
|
||||
a_Connection.SendStatusAndReason(500, "Bad UserData");
|
||||
@ -244,6 +244,7 @@ void cWebAdmin::HandleWebadminRequest(cHTTPConnection & a_Connection, cHTTPReque
|
||||
// Wrap it all up for the Lua call:
|
||||
AString Template;
|
||||
HTTPTemplateRequest TemplateRequest;
|
||||
TemplateRequest.Request.URL = a_Request.GetURL();
|
||||
TemplateRequest.Request.Username = a_Request.GetAuthUsername();
|
||||
TemplateRequest.Request.Method = a_Request.GetMethod();
|
||||
TemplateRequest.Request.Path = BareURL.substr(1);
|
||||
|
@ -50,9 +50,18 @@ struct HTTPRequest
|
||||
typedef std::map< std::string, std::string > StringStringMap;
|
||||
typedef std::map< std::string, HTTPFormData > FormDataMap;
|
||||
|
||||
/** The entire URL presented to the HTTP server. */
|
||||
AString URL;
|
||||
|
||||
/** HTTP method used for the request ("GET", "POST" etc.) */
|
||||
AString Method;
|
||||
|
||||
/** The Path part of the request's URL (excluding GET params). */
|
||||
AString Path;
|
||||
|
||||
/** Name of the logged-in user. Empty if not logged in. */
|
||||
AString Username;
|
||||
|
||||
// tolua_end
|
||||
|
||||
/** Parameters given in the URL, after the questionmark */
|
||||
|
Loading…
Reference in New Issue
Block a user