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
req.accepts: */* wildcard fix #1020
Conversation
Look for '*/*' anywhere in the Accept header instead of only supporting it when it's the exact value of the header. IE8 sends: Accept: image/gif, image/jpeg, image/pjpeg, image/pjpeg, application/x-shockwave-flash, application/x-ms-application, application/x-ms-xbap, application/vnd.ms-xpsdocument, application/xaml+xml, */* for which req.accepts('html') returned false.
In version 2.5.9 (latest tagged version you get with npm install) req.accept('json') will always return true due to this fix. I saw some changes on the master, but I haven't tested it yet. I downgraded to 2.5.4 for now. We are using req.accept('json') in order to determine if it is an ajax request or a user who actually loads the page (serving html). There should be a way to determine if a mime type was explicitly sent by the client or implicitly sent. One approach would be to add a flag, 'implicit' set to false by default to preserve behavior from 2.5.4 and below but also allow to check for the scenario described above. |
// when Accept does not exist, or is '*/*' return true | ||
if (!accept || '*/*' == accept) { | ||
// when Accept does not exist, or contains '*/*' return true | ||
if (!accept || ~accept.indexOf('*/*')) { |
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.
will cause it to always return true since most browsers send this by default with every request.
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's as per RFC. If the agent is giving you / then it's fine with anything
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.
in 3x you can also now do req.accepts(['json', 'html'])
which returns the acceptable type (if any) which is probably more what you're looking for, this variant will not return a random value even with /, that's up to the user to default
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.
Ok so in that example for 3x you gave it will only return true if html or
json are listed explicitly?
On 2012-04-15 12:07 PM, "TJ Holowaychuk" <
reply@reply.github.com>
wrote:
@@ -135,8 +135,8 @@ req.accepts = function(type){
// normalize extensions ".json" -> "json"
...
in 3x you can also now doreq.accepts(['json', 'html'])
which returns the
acceptable type (if any) which is probably more what you're looking for,
this variant will not return a random value even with /, that's up to the
user to default
Reply to this email directly or view it on GitHub:
https://github.com/visionmedia/express/pull/1020/files#r686089
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.
not necessarily explicitly, for example if Accept contained "text/" it'll still match, but if there is not a match (excluding */) it'll return undefined. At least that's how it is right now, but I dont think that's necessarily "correct". We're probably better off to return the first value in that case
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.
let's open a new issue to discuss this it's way too cluttered in here
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.
Event Details: Test Driven Development is software development methodology based on "test first" approach. That means that before even writing a line of code we need to write a test for it. Benefits of applying TDD includes: * Increase development...
Read More
Share this event on Facebook
and Twitter
We hope you can make it!Cheers,Winnipeg.js
Event Summary:
Event: Test Driven Development in JS
Date: Tuesday, October 30, 2012 from 6:00 PM to 9:00 PM (CDT)
Location: <b>Smart Park Event Center, University of Manitoba</b><br />1 Research Rd<br />Winnipeg, MB R3T 6E3<br />Canada<br />
Event Details:
Event Details:
Test Driven Development is software development methodology based on "test first" approach.
That means that before even writing a line of code we need to write a test for it.
Benefits of applying TDD includes:
- Increase development confidence
- Improve quality of the code and use quality as a driver
- Regression testing at any point
- Automatic documentation
- Bring back the joy of coding!
The idea seems fine for languages like C# however what about Javascript? Javascript is quite a popular language (if not the most) so, are we condemned to test the UI every time I want to test my JS code? Why can't we do TDD with it?
Of course we can! Join me on a session to discuss how to start with Jasmine, a JS library for testing in general, that provides great syntax to use TDD. I assure you your JS code will never be the same!
About the Speaker:
Amir Barylko started his career in 1994 working for IBM as a senior developer while he was finishing his Masters degree in computer science. Since then he worked as team leader and architect for the past 15 years.
Having started with languages like C++ and Java he spent many years coding in C# and training other developers in topics such domain modeling, abstractions, patterns, automation, dependency injection, testing, etc.
Being an incurable geek, always thirsty for knowledge, his passion for technology moved him towards Ruby on Rails a few years ago, becoming an advocate of RoR web development. Also following he's teaching passion he did his first RoR training a year ago, and recently a TDD training with great reviews.
Amir is a rare combination of high technical skills, lots of experience in a wide range of platforms, exceptional presentation skills and great sense of humor. His presentations are always rich in content and fun to attend.
Hosted By:
Winnipeg.js
Register Online:
More information and online registration are available here:
http://www.eventbrite.com/event/4657304122/?ref=enivte001&invite=MjY1MzU1Ny9yZXBseStwLTY4NjA4OS0yOWE1ODg0OWEyNjBkNTM4Y2YwNjA3ZmZjMzUzYjIyOWJiNjIxZWFmLTEzODY5NjZAcmVwbHkuZ2l0aHViLmNvbS8w
Collect event fees online with Eventbrite
http://www.eventbrite.com
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.
Event Details: Test Driven Development is software development methodology based on "test first" approach. That means that before even writing a line of code we need to write a test for it. Benefits of applying TDD includes: * Increase development...
Read More
Share this event on Facebook
and Twitter
We hope you can make it!Cheers,Winnipeg.js
Event Summary:
Event: Test Driven Development in JS
Date: Tuesday, October 30, 2012 from 6:00 PM to 9:00 PM (CDT)
Location: <b>Smart Park Event Center, University of Manitoba</b><br />1 Research Rd<br />Winnipeg, MB R3T 6E3<br />Canada<br />
Event Details:
Event Details:
Test Driven Development is software development methodology based on "test first" approach.
That means that before even writing a line of code we need to write a test for it.
Benefits of applying TDD includes:
- Increase development confidence
- Improve quality of the code and use quality as a driver
- Regression testing at any point
- Automatic documentation
- Bring back the joy of coding!
The idea seems fine for languages like C# however what about Javascript? Javascript is quite a popular language (if not the most) so, are we condemned to test the UI every time I want to test my JS code? Why can't we do TDD with it?
Of course we can! Join me on a session to discuss how to start with Jasmine, a JS library for testing in general, that provides great syntax to use TDD. I assure you your JS code will never be the same!
About the Speaker:
Amir Barylko started his career in 1994 working for IBM as a senior developer while he was finishing his Masters degree in computer science. Since then he worked as team leader and architect for the past 15 years.
Having started with languages like C++ and Java he spent many years coding in C# and training other developers in topics such domain modeling, abstractions, patterns, automation, dependency injection, testing, etc.
Being an incurable geek, always thirsty for knowledge, his passion for technology moved him towards Ruby on Rails a few years ago, becoming an advocate of RoR web development. Also following he's teaching passion he did his first RoR training a year ago, and recently a TDD training with great reviews.
Amir is a rare combination of high technical skills, lots of experience in a wide range of platforms, exceptional presentation skills and great sense of humor. His presentations are always rich in content and fun to attend.
Hosted By:
Winnipeg.js
Register Online:
More information and online registration are available here:
http://www.eventbrite.com/event/4657304122/?ref=enivte001&invite=MjY1MzU1Ny9yZXBseStwLTY4NjEzMS1lOGE1Y2I3ODFiNDM4NWQ5ZTFiNWQzMmUzZWVhZGMxODMxOTVmZjFiLTEzODY5NjZAcmVwbHkuZ2l0aHViLmNvbS8w
Collect event fees online with Eventbrite
http://www.eventbrite.com
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.
wtf?
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.
hahahah what the
Look for
*/*
anywhere in the Accept header instead of only supporting it when it's the exact value of the header.IE8 sends:
for which
req.accepts('html')
returnedfalse
.This bug doesn't exist on the master branch.