m2php icon indicating copy to clipboard operation
m2php copied to clipboard

Add transparent support for the tnetstring protocol

Open dermoth opened this issue 13 years ago • 2 comments

Similar to the python reference library. tnetstring parser from: https://github.com/jessedp/tnetstrings-php (with minor changes)

Tested with request_payloads.txt (from Mongrel2 Python tests)

dermoth avatar Mar 01 '12 08:03 dermoth

Hold on, this may not be as simple as it looked... I've had to make other changes that I'm guessing would break the old protocol. I had to patch stuff like this in my code and in Request.php:

-        if ($this->headers->METHOD == 'JSON') {
-            return $this->data['type'] == 'disconnect';
+        if ($this->headers['METHOD'] == 'JSON') {
+            return ($this->data->type == 'disconnect');

If we wanted something really transparent we'd have to write some wrappers around it. In the long term I would try to aim at getting the JSON data parsed an array rather that using methods; what you you think?

The tests I've run checked that the data was parsed properly, not that is would be available using the same methods :(

Thanks

dermoth avatar Mar 02 '12 08:03 dermoth

As expected the change pointed out was breaking JSON - so I made JSON return plain arrays as well and all if fine.

So both protocols have been tested - with a real handler, still haven't tried to get the unit tests to run - with GET's (with JSON being slightly faster as it decodes in C), I haven't tested POSTs yet.

Thanks

dermoth avatar Mar 03 '12 22:03 dermoth