milesj / utility

[Deprecated] A CakePHP plugin for common utility classes.
MIT License
69 stars 24 forks source link

Ajax component can't handle responses bigger than 4096 #33

Open highstrike opened 9 years ago

highstrike commented 9 years ago

If you have a response bigger than 4096 then the request type will be text/html instead of application/json

Tested on CakePHP 2.5.7

milesj commented 9 years ago

I doubt this is anything that I am doing, the component is pretty straight forward. I'll look into it.

highstrike commented 9 years ago

found anything interesting? :)

milesj commented 9 years ago

Nope. There's nothing in my code that would cause this. Looked into Cake's RequestHandler and didn't find anything there either. Perhaps it's a server configuration?

highstrike commented 9 years ago

If I put a header content type application json right in your case json on the last function then it works, but I don't wana do that, did you try it on your server and you could do more than 4096?

milesj commented 9 years ago

I have not as I don't use CakePHP anymore and have no applications running it.

The RequestHandler sets the content type, not my component.

https://github.com/milesj/utility/blob/master/Controller/Component/AjaxHandlerComponent.php#L147 https://github.com/cakephp/cakephp/blob/master/lib/Cake/Controller/Component/RequestHandlerComponent.php#L667

You're passing JSON to respond() correct?

I also wonder if it's failing somewhere else in Cake, like the Response class.

https://github.com/cakephp/cakephp/blob/master/lib/Cake/Network/CakeResponse.php#L709

highstrike commented 9 years ago

I left your line 147 as it is, and im doing header('Content-Type: application/json'); before this line: https://github.com/milesj/utility/blob/master/Controller/Component/AjaxHandlerComponent.php#L186

Would you be willing to setup a simple cake project and try it out? Thank you :)

milesj commented 9 years ago

When I have time (which won't be anytime soon).

I'd try debugging why RequestHandler/Response isn't setting the content type. Forcing the type through headers is the wrong approach.

highstrike commented 9 years ago

I know it's the wrong approach but it works.

I've tried debugging the request handler / response but got nowhere, at the end $ctype was application/json and $type was json. Even after all that the header content type in the browser was showing up as text/html... so can't really think of anything else =/

milesj commented 9 years ago

I wonder if it's happening further down the chain.

What about setting the content type manually from your action? Instead of the component?

highstrike commented 9 years ago

haven't tried from controller / action yet... will do when i get to work tomorrow.

highstrike commented 9 years ago

Haven't had a chance to try it out yet, deadlines at work, last 2 days before holidays, couldn't even touch that specific cake project...

milesj commented 9 years ago

Same. I probably won't be able to look at this until after the holidays.