Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

webserver: add support for passing JSON-RPC requests through HTTP GET arguments #1506

Merged
merged 1 commit into from

1 participant

@Montellese
Owner

In addition to the existing support for sending JSON-RPC requests through HTTP POST requests to the webserver this commit adds support for JSON-RPC requests through HTTP GET arguments. There are two ways of doing a request through HTTP GET:

  1. Pass a full URL-encoded JSON-RPC request with the "request" argument
  2. Pass the name of the JSON-RPC method to be executed with the "method" argument. This does not allow to send parameters.

I made this based on a discussion with @amet on IRC where he stated that he will miss the way to execute a HTTP-API command simply by calling a HTTP URL once the HTTP-API has been completely replaced by JSON-RPC. So I added this functionality which will make this possible.

@Montellese Montellese webserver: add support for passing JSON-RPC requests through HTTP GET…
… arguments

In addition to the existing support for sending JSON-RPC requests through HTTP
POST requests to the webserver this commit adds support for JSON-RPC requests
through HTTP GET arguments by passing a full URL-encoded JSON-RPC request in the "request" GET argument.
331afa3
@Montellese
Owner

After a discussion with @topfs2 on IRC we have decided to not add the "method" argument shortcut because it's not really JSON-RPC anymore and doesn't allow for parameters etc. Therefore the only way to call a JSON-RPC method through HTTP GET is by url-encoding the request and passing it in the "request" GET argument.

@Montellese Montellese was assigned
@Montellese Montellese merged commit f674404 into from
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Oct 1, 2012
  1. @Montellese

    webserver: add support for passing JSON-RPC requests through HTTP GET…

    Montellese authored
    … arguments
    
    In addition to the existing support for sending JSON-RPC requests through HTTP
    POST requests to the webserver this commit adds support for JSON-RPC requests
    through HTTP GET arguments by passing a full URL-encoded JSON-RPC request in the "request" GET argument.
This page is out of date. Refresh to see the latest.
Showing with 18 additions and 1 deletion.
  1. +18 −1 xbmc/network/httprequesthandler/HTTPJsonRpcHandler.cpp
View
19 xbmc/network/httprequesthandler/HTTPJsonRpcHandler.cpp
@@ -39,6 +39,7 @@ bool CHTTPJsonRpcHandler::CheckHTTPRequest(const HTTPRequest &request)
int CHTTPJsonRpcHandler::HandleHTTPRequest(const HTTPRequest &request)
{
CHTTPClient client;
+ bool isRequest = false;
if (request.method == POST)
{
string contentType = CWebServer::GetRequestHeaderValue(request.connection, MHD_HEADER_KIND, MHD_HTTP_HEADER_CONTENT_TYPE);
@@ -50,8 +51,24 @@ int CHTTPJsonRpcHandler::HandleHTTPRequest(const HTTPRequest &request)
return MHD_YES;
}
- m_response = CJSONRPC::MethodCall(m_request, request.webserver, &client);
+ isRequest = true;
}
+ else if (request.method == GET)
+ {
+ map<string, string> arguments;
+ if (CWebServer::GetRequestHeaderValues(request.connection, MHD_GET_ARGUMENT_KIND, arguments) > 0)
+ {
+ map<string, string>::const_iterator argument = arguments.find("request");
+ if (argument != arguments.end() && !argument->second.empty())
+ {
+ m_request = argument->second;
+ isRequest = true;
+ }
+ }
+ }
+
+ if (isRequest)
+ m_response = CJSONRPC::MethodCall(m_request, request.webserver, &client);
else
{
// get the whole output of JSONRPC.Introspect
Something went wrong with that request. Please try again.