Opened 4 years ago

Closed 3 years ago

#11321 closed defect (fixed)

XML response has incorrect Content-Type on some errors

Reported by: Matt Muller Owned by: Odd Simon Simonsen
Priority: normal Component: XmlRpcPlugin
Severity: normal Keywords:
Cc: Olemis Lang Trac Release: 0.12


curl -v -H "Content-Type: text/xml" --data @body.xml http://$USER:$PASS@trac/login/xmlrpc

POST /login/xmlrpc HTTP/1.1
Authorization: Basic 
User-Agent: curl/7.24.0 (x86_64-apple-darwin12.0) libcurl/7.24.0 
Host: trac
Accept: */*
Content-Type: text/xml
Content-Length: 273

The XMLRPC plugin is supposed to detect the Content-Type and send back a response with the same Content-Type:

HTTP/1.1 200 OK
Date: Thu, 12 Sep 2013 18:23:23 GMT
Server: Apache/2.2.22
Content-Length: 2509
Vary: Accept-Encoding
Content-Type: text/xml

However, if I send an XMLRPC request that attempts to perform an invalid action on a ticket (for example, the workflow does not allow a ticket with the status 'new' to be set as 'in_QA'), the plugin sends back a different Content-Type (though still with a 200 OK header):

HTTP/1.1 200 OK
Date: Thu, 12 Sep 2013 18:24:20 GMT
Server: Apache/2.2.22
Content-Length: 345
Content-Type: application/xml

While this might not be a problem for some client libraries, the Ruby XMLRPC::Client library requires a text/xml content type.

Suspected Cause/Solution:

On line 130 of tracrpc/, this is how the plugin sends a (correct) response for some specified error codes:

130 self._send_response(req, xmlrpclib.dumps(fault), rpcreq['mimetype'])

On line 140, where the (incorrect) response is sent for all other types of errors, the plugin leaves out the rpcreq['mimetype'] argument:

140 self._send_response(req,
141      xmlrpclib.dumps(
142            xmlrpclib.Fault(err_code,
143                 "'%s' while executing '%s()'" % (str(e), method))))

I believe changing this to the following will fix the problem:

140 self._send_response(req,
141       xmlrpclib.dumps(
142              xmlrpclib.Fault(err_code,
143                     "'%s' while executing '%s()'" % (str(e), method))), rpcreq['mimetype'])

Attachments (0)

Change History (3)

comment:1 Changed 4 years ago by Olemis Lang

This is an interesting issue I'll write a test case to reproduce this situation . I'm sure osimons will add comments on this subject soon .

Thanks for reporting this issue.

comment:2 Changed 3 years ago by Ben Allen

I can verify that manually applying this patch to the current codebase (r13203) resolved my problems running XMLRPC calls from Ruby scripts. That particular call to the _send_response function is the only one in that file that doesn't pass rpcreq['mimetype'] as the third argument.

comment:3 Changed 3 years ago by Odd Simon Simonsen

Resolution: fixed
Status: newclosed

In 13637:

XmlRpcPlugin: Fixed missing mimetype when returning error for unknown faults. Closes #11321.

Thanks to mattinflection for report + patch, and to AllenB for verification.

Modify Ticket

Change Properties
Set your email in Preferences
as closed The owner will remain Odd Simon Simonsen.
The resolution will be deleted. Next status will be 'reopened'.

Add Comment

E-mail address and name can be saved in the Preferences.

Note: See TracTickets for help on using tickets.