jshttp / accepts

Higher-level content negotiation
MIT License
252 stars 42 forks source link

RangeError: Maximum call stack size exceeded #8

Closed charliev closed 9 years ago

charliev commented 9 years ago

Hi,

I am getting this RangeError: Maximum call stack size exceeded when testing with non-existent accept-headers. that is:

I tried

try {
  type = accept.types('html', 'json');
} catch(e) {
// RangeError: Maximum call stack size exceeded
}

to get around the problem, but it still crashes the process I haven't tried to pimp the request.headers yet, I don't know if it can be done but it looks like it shouldn't

k.

dougwilson commented 9 years ago

Hi, can you real quick post fuller code that I can run and what version of this module you are using, please? For example, code code necessary for me to create "accept" variable to run your code above.

charliev commented 9 years ago

Weird, It must be something I'm doing wrong, this is what my code is basically doing:

var accepts = require('accepts');

function test(headers) {
  var accept = accepts({
    headers: headers
  });
  switch(accept.types('html', 'json')) {
    case 'html':
      console.log('html');
      break;
    case 'json':
      console.log('json');
      break;
    default:
      console.log('not acceptable');
  }
}

test({});
test({
  accept: 'application/json'
});
test({
  accept: 'text/plain'
});
test({
  accept: 'foo/bar'
});

but it works fine, should've tested that first. I desperately need some sleep now, will look at it over the weekend. Close at will; sorry to have bothered you. k.

charliev commented 9 years ago

my bad: I had an infinite recursion in the default case

dougwilson commented 9 years ago

It's no problem. I'm glad you figured it out :)