-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Added jsonp support #35
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
I'm not worried about modifying it a bit as this is still in major version zero. I'll just bump the minor release for this. Instead of the |
Yeah cool. I wasn't sure if you were ok with making the response available to every formatter. Ill update sometime this week. |
Signed-off-by: Jason Lewis <jason.lewis1991@gmail.com>
- All response formats should now have the request accessible
Hiya, Have a look and let me know. If thats ok. |
yeap, jsonp is needed a lot |
$response->setStatusCode(200); | ||
} | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you please explain this? Why is the response being forced to return as "200 OK"?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah its annoying but i was working with another developer and they were
implementing something in phone-gap.
Apparently when they made jsonp requests and the response status code was a
non standard one eg. 422, the response body would be dropped.
Using a 200 ensured that the body was delivered. I havent had time to
verify this personally, so perhaps someone else can confirm / shed some
light on this edge case.
On Thu, May 22, 2014 at 9:38 PM, Jason Lewis notifications@github.comwrote:
In src/Routing/Router.php:
$response = Response::makeFromExisting($response)->morph($this->requestedFormat); }
// Force the response to always return "200 OK"
// Chances are if the client is requesting jsonp their browser
// wont implement 422 etc and will drop the body
if ($this->requestedFormat == 'jsonp') {
if (!in_array($response->getStatusCode(), [404, 200])) {
$response->setStatusCode(200);
}
}
Can you please explain this? Why is the response being forced to return as
"200 OK"?—
Reply to this email directly or view it on GitHubhttps://github.com//pull/35/files#r12945612
.
Arnold Almeida
+61 432 149 788
arnold@floatingpoints.com.au
Floating Points // Digital Direction
floatingpoints.com.au
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah I'm not too sure on this part. Seems a bit hacky to me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
422 is a client error. 200 means everything is fine.
This is terrible. I have a whole slide about the problems this causes in my talk.
Please don't do this.
422 is often used for validation, but it is reserved for WebDAV and not officially in the HTTP spec. Just tell whoever is using PhoneGap and 422's to switch to 400 and you'll be fine.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The 422's I believe are hardcoded into the dingo exceptions for store, update, and delete. But I could be mistaken.
---Hunter Skrasekhunterskrasek@me.com
On May 23, 2014 at 5:16:30 PM CDT, Phil Sturgeon notifications@github.com wrote:In src/Routing/Router.php: > $response = Response::makeFromExisting($response)->morph($this->requestedFormat); > } > > + // Force the response to always return "200 OK" > + // Chances are if the client is requesting jsonp their browser > + // wont implement 422 etc and will drop the body > + if ($this->requestedFormat == 'jsonp') { > + if (!in_array($response->getStatusCode(), [404, 200])) { > + $response->setStatusCode(200); > + } > + } > + 422 is a client error. 200 means everything is fine. This is terrible. I have a whole slide about the problems this causes in my talk. Please don't do this. 422 is often used for validation, but it is reserved for WebDAV and not officially in the HTTP spec. Just tell whoever is using PhoneGap and 422's to switch to 400 and you'll be fine. —Reply to this email directly or view it on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That should be changed too then. :)
--
Phil Sturgeon
On May 24, 2014 at 12:02:18 AM, Hunter Skrasek (notifications@github.com) wrote:
In src/Routing/Router.php:
$response = Response::makeFromExisting($response)->morph($this->requestedFormat); }
// Force the response to always return "200 OK"
// Chances are if the client is requesting jsonp their browser
// wont implement 422 etc and will drop the body
if ($this->requestedFormat == 'jsonp') {
if (!in_array($response->getStatusCode(), [404, 200])) {
$response->setStatusCode(200);
}
}
The 422's I believe are hardcoded into the dingo exceptions for store, update, and delete. But I could be mistaken.
…
—
Reply to this email directly or view it on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for clearing that up Phil.
Yeah the 422's are coming from the api internals. Will amend and fix in a
bit. If 422 is for WebDAV is make sense for phonegap not to support it.
On Sat, May 24, 2014 at 9:03 AM, Phil Sturgeon notifications@github.comwrote:
In src/Routing/Router.php:
$response = Response::makeFromExisting($response)->morph($this->requestedFormat); }
// Force the response to always return "200 OK"
// Chances are if the client is requesting jsonp their browser
// wont implement 422 etc and will drop the body
if ($this->requestedFormat == 'jsonp') {
if (!in_array($response->getStatusCode(), [404, 200])) {
$response->setStatusCode(200);
}
}
That should be changed too then. :)
-- Phil Sturgeon On May 24, 2014 at 12:02:18 AM, Hunter Skrasek (
notifications@github.com) wrote: In src/Routing/Router.php:
$response =
Response::makeFromExisting($response)->morph($this->requestedFormat); } +
// Force the response to always return "200 OK" + // Chances are if the
client is requesting jsonp their browser + // wont implement 422 etc and
will drop the body + if ($this->requestedFormat == 'jsonp') { + if
(!in_array($response->getStatusCode(), [404, 200])) { +
$response->setStatusCode(200); + } + } +
The 422's I believe are hardcoded into the dingo exceptions for store,
update, and delete. But I could be mistaken. … — Reply to this email
directly or view it on GitHub.—
Reply to this email directly or view it on GitHubhttps://github.com//pull/35/files#r13022269
.
Arnold Almeida
+61 432 149 788
arnold@floatingpoints.com.au
Floating Points // Digital Direction
floatingpoints.com.au
- Use 400 instead of 422 for increased compatibility for clients. See comments in dingo#35 for rational.
Do i need to do anything else ? |
I'll pull this down locally and merge it. There's a couple things that are changing along the way. |
👍 |
Can someone provide an example of using this? Thank you! |
- Use 400 instead of 422 for increased compatibility for across API clients. See comments in dingo#35 for rational.
+1 @ingro |
All you need to do is:
Note that when |
Heya. Here is a semi nice way of providing jsonp support without having to modify too much.