mirror of https://github.com/aria2/aria2
				
				
				
			Return appropriate HTTP status code on RPC failure.
In this change, we return 404 if the request path is neither /json-rpc nor /rpc. If XML feature is not enabled and /rpc is requested, return 404. If XML parser failed, return 400. JSON parser failure has been handled well in the existing code.pull/20/head
							parent
							
								
									8ebba32fd9
								
							
						
					
					
						commit
						afcd95dec7
					
				| 
						 | 
				
			
			@ -163,7 +163,18 @@ bool HttpServerBodyCommand::execute()
 | 
			
		|||
        if(reqPath == "/rpc") {
 | 
			
		||||
#ifdef ENABLE_XML_RPC
 | 
			
		||||
          std::string body = httpServer_->getBody();
 | 
			
		||||
          rpc::RpcRequest req = rpc::xmlParseMemory(body.c_str(), body.size());
 | 
			
		||||
          rpc::RpcRequest req;
 | 
			
		||||
          try {
 | 
			
		||||
            req = rpc::xmlParseMemory(body.c_str(), body.size());
 | 
			
		||||
          } catch(RecoverableException& e) {
 | 
			
		||||
            A2_LOG_INFO_EX
 | 
			
		||||
              (fmt("CUID#%lld - Failed to parse XML-RPC request",
 | 
			
		||||
                   getCuid()),
 | 
			
		||||
               e);
 | 
			
		||||
            httpServer_->feedResponse(400);
 | 
			
		||||
            addHttpServerResponseCommand();
 | 
			
		||||
            return true;
 | 
			
		||||
          }
 | 
			
		||||
          SharedHandle<rpc::RpcMethod> method =
 | 
			
		||||
            rpc::RpcMethodFactory::create(req.methodName);
 | 
			
		||||
          A2_LOG_INFO(fmt("Executing RPC method %s", req.methodName.c_str()));
 | 
			
		||||
| 
						 | 
				
			
			@ -172,7 +183,10 @@ bool HttpServerBodyCommand::execute()
 | 
			
		|||
          std::string responseData = rpc::toXml(res, gzip);
 | 
			
		||||
          httpServer_->feedResponse(responseData, "text/xml");
 | 
			
		||||
          addHttpServerResponseCommand();
 | 
			
		||||
#endif // ENABLE_XML_RPC
 | 
			
		||||
#else // !ENABLE_XML_RPC
 | 
			
		||||
          httpServer_->feedResponse(404);
 | 
			
		||||
          addHttpServerResponseCommand();
 | 
			
		||||
#endif // !ENABLE_XML_RPC
 | 
			
		||||
          return true;
 | 
			
		||||
        } else if(reqPath == "/jsonrpc") {
 | 
			
		||||
          std::string callback;
 | 
			
		||||
| 
						 | 
				
			
			@ -223,6 +237,8 @@ bool HttpServerBodyCommand::execute()
 | 
			
		|||
          }
 | 
			
		||||
          return true;
 | 
			
		||||
        } else {
 | 
			
		||||
          httpServer_->feedResponse(404);
 | 
			
		||||
          addHttpServerResponseCommand();
 | 
			
		||||
          return true;
 | 
			
		||||
        }
 | 
			
		||||
      } else {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -38,6 +38,10 @@ namespace aria2 {
 | 
			
		|||
 | 
			
		||||
namespace rpc {
 | 
			
		||||
 | 
			
		||||
RpcRequest::RpcRequest()
 | 
			
		||||
  : jsonRpc(false)
 | 
			
		||||
{}
 | 
			
		||||
 | 
			
		||||
RpcRequest::RpcRequest(const std::string& methodName,
 | 
			
		||||
                       const SharedHandle<List>& params)
 | 
			
		||||
  : methodName(methodName), params(params), jsonRpc(false)
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -51,6 +51,8 @@ struct RpcRequest {
 | 
			
		|||
  SharedHandle<ValueBase> id;
 | 
			
		||||
  bool jsonRpc;
 | 
			
		||||
 | 
			
		||||
  RpcRequest();
 | 
			
		||||
 | 
			
		||||
  RpcRequest(const std::string& methodName,
 | 
			
		||||
             const SharedHandle<List>& params);
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue