encoding.js 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. (function() {
  2. var configuration, preferredEncodings, testConfigurations, testCorrectEncoding, _i, _len,
  3. _this = this;
  4. preferredEncodings = require('../lib/encoding').preferredEncodings;
  5. this["Should return identity encoding when no encoding is provided"] = function(test) {
  6. test.deepEqual(preferredEncodings(null), ['identity']);
  7. return test.done();
  8. };
  9. this["Should include the identity encoding even if not explicity listed"] = function(test) {
  10. test.ok(preferredEncodings('gzip').indexOf('identity') !== -1);
  11. return test.done();
  12. };
  13. this["Should not return identity encoding if q = 0"] = function(test) {
  14. test.ok(preferredEncodings('identity;q=0').indexOf('identity') === -1);
  15. return test.done();
  16. };
  17. testCorrectEncoding = function(c) {
  18. return _this["Should return " + c.selected + " for accept-encoding header " + c.accept + " with provided encoding " + c.provided] = function(test) {
  19. test.deepEqual(preferredEncodings(c.accept, c.provided), c.selected);
  20. return test.done();
  21. };
  22. };
  23. testConfigurations = [
  24. {
  25. accept: 'gzip',
  26. provided: ['identity', 'gzip'],
  27. selected: ['gzip', 'identity']
  28. }, {
  29. accept: 'gzip, compress',
  30. provided: ['compress'],
  31. selected: ['compress']
  32. }, {
  33. accept: 'deflate',
  34. provided: ['gzip', 'identity'],
  35. selected: ['identity']
  36. }, {
  37. accept: '*',
  38. provided: ['identity', 'gzip'],
  39. selected: ['identity', 'gzip']
  40. }, {
  41. accept: 'gzip, compress',
  42. provided: ['compress', 'identity'],
  43. selected: ['compress', 'identity']
  44. }, {
  45. accept: 'gzip;q=0.8, identity;q=0.5, *;q=0.3',
  46. provided: ['identity', 'gzip', 'compress'],
  47. selected: ['gzip', 'identity', 'compress']
  48. }, {
  49. accept: 'gzip;q=0.8, compress',
  50. provided: ['gzip', 'compress'],
  51. selected: ['compress', 'gzip']
  52. }, {
  53. accept: 'gzip;q=0.8, compress',
  54. provided: null,
  55. selected: ['compress', 'gzip', 'identity']
  56. }
  57. ];
  58. for (_i = 0, _len = testConfigurations.length; _i < _len; _i++) {
  59. configuration = testConfigurations[_i];
  60. testCorrectEncoding(configuration);
  61. }
  62. }).call(this);