scripting / xml-rpc

XML-RPC client and server in JavaScript.
MIT License
61 stars 28 forks source link

XMLRPC boolean encoding #8

Closed frln closed 5 years ago

frln commented 5 years ago

The client library will encode the boolean like <boolean> true </boolean> but the spec give <boolean> 1 </boolean> as an example. Should an XMLRPC server support both encoding?

frln commented 5 years ago

I need to test this but I think that the standard xmlrpc library of python will only accept 1 and 0 for boolean https://github.com/python/cpython/blob/3.7/Lib/xmlrpc/client.py#L722

scripting commented 5 years ago

For servers

Your server should handle any reasonable representation of a value. My server understands numbers or literals for booleans.

This follows half of Postel's Robustness Principle -- be liberal in what you accept.

For clients

At this stage, almost 20 years since the protocol was first deployed, you should start with the spec, and if you're not sure how to proceed, look at the examples in the spec and do what they do. Because that's likely what the people who came before did. Certainly all servers support the spec and the examples.

If it's still not clear, I'd look at the Python implementation as you're doing, also PHP or Java and do what they do. Servers would be certain to have tested with those three big implementations.

I have just published a JavaScript implementation (it's in this repo), and I checked, it generates the literal "true" for true and "false" for false.

But it's very new, and I don't know of anyone who has deployed with it, so I could change what it does.

frln commented 5 years ago

My first message was unclear, I'm actually trying to use the javascript client implementation to interact with the external api of Odoo, an ERP that apparently use the python library for managing XMLRPC request. The server threw at me an internal error that was fixed by changing the encoding from true/false to 1/0.

After some research, it seems that only PHP handle both true and 1. This Apache Java library documentation only mention 0 and 1 for boolean. And as stated above it seems that the python library only accept 0 and 1 without throwing an error.

scripting commented 5 years ago

I figured it was something like that. :-)