request / caseless Goto Github PK
View Code? Open in Web Editor NEWCaseless object set/get/has, very useful when working with HTTP headers.
License: Apache License 2.0
Caseless object set/get/has, very useful when working with HTTP headers.
License: Apache License 2.0
get incorrectly matches other headers containing name. See this example:
var assert = require('assert'),
caseless = require('caseless');
var c = caseless({
'Foo': 'bar',
'Not-Foo': 'baz'
});
assert.equal(c.get('Foo'), 'bar');
which gives output:
assert.js:92
throw new assert.AssertionError({
^
AssertionError: "baz" == "bar"
at Object. (bug.js:9:8)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Function.Module.runMain (module.js:497:10)
at startup (node.js:119:16)
at node.js:906:3
Very similar to: request/request#825 ;-)
Hello @mikeal
Currently I'm using this component under version 0.9.0 and 0.6.0 which seems not to be present on your repository. The only information regarding the license for the version 0.9.0 and lower ones is the statement present inside the package.json file, which is "BSD".
Would you please be more specific regarding the license for the version 0.9.0 and older ones? What license will apply for those versions, Apache 2.0 (as I can see is the master license) or the BSD one? And in case of BSD which version?
Thank you!
Just a small thing, and you don't have to agree with me but, I consider that in these cases it would be more readable an API with a third param as an options object like:
set(key, value[, {clobber: true}]);
since when in code you know what that false/true means:
c.set('a-HEADER', 'more', {clobber: false});
What do you think?
I sent a PR #29 to fix an issue where del() won't delete duplicates if they exist. I'm assuming since set() and get() avoid duplicates, delete should be doing the same. You can see in more details in the tests the behavior.
I also updated the readme.
Could you please clarify the license this software is distributed under?
package.json
says BSD
, but there is no license file in the repo. Since BSD family licenses typically require distributing an exact copy of the license alongside the software, and there isn't one canonical version of the BSD license, I can't get the legal department OK to use this software.
I know it's pedantic, but you know how lawyers are =(
Thanks!
This would allow building whitelists and blacklists more easily, for example see request/request#1367
http
and https
module implement hasHeader
which returns a boolean.
But caseless returns either false or the header name which is not the same.
https://www.npmjs.com/package/caseless#haskey
Caseless.prototype.has = function (name) {
var keys = Object.keys(this.dict)
, name = name.toLowerCase()
;
for (var i=0;i<keys.length;i++) {
if (keys[i].toLowerCase() === name) return keys[i]
}
return false
}
Same for the official HTTP APIs in browsers, see https://developer.mozilla.org/en-US/docs/Web/API/Headers/has
Hey,
Thanks for the good effort in building this library. We would like to use your node in our project.
Can you let us know what BSD License have been assigned to this library?
Thanks
Kandy
Was version 0.9.0 removed for some particular reason?
Our CI environment is failing when installing 0.9.0.
Caseless is a dependency of jspm-github making jspm builds failing.
Line 40 in 9807910
In the above line 'than' should be 'that'.
This way you could pass an instance of caseless
to the headers
option of request
.
The following line tries to call c.getHeader
but it should be c.get
: https://github.com/mikeal/caseless/blob/d7a9316a9b6bad70a2e6ee3f4fedf7b38ade91b9/index.js#L58
Hello!
When using swap
function, if casing of passed argument matches the current header, it simply gets removed. It is very easy to reproduce
options.headers = {'Content-Type':'something'}
normalizedHeaders = caseless options.headers
normalizedHeaders.swap 'Content-Type'
Content-Type is now vanished.
Hi @mikeal I'm unable to install caseless with
npm install caseless
NPM error:
npm ERR! Error: EACCES, mkdir '/Users/n/.npm/caseless/0.8.0'
npm ERR! { [Error: EACCES, mkdir '/Users/n/.npm/caseless/0.8.0']
npm ERR! errno: 3,
npm ERR! code: 'EACCES',
npm ERR! path: '/Users/n/.npm/caseless/0.8.0',
npm ERR! parent: 'request' }
npm ERR!
npm ERR! Please try running this command again as root/Administrator.
npm ERR! System Darwin 13.3.0
npm ERR! command "node" "/usr/local/bin/npm" "install"
npm ERR! cwd /Users/n/play/hapi_template
npm ERR! node -v v0.10.33
npm ERR! npm -v 1.4.28
npm ERR! path /Users/n/.npm/caseless/0.8.0
npm ERR! code EACCES
npm ERR! errno 3
npm ERR! stack Error: EACCE
Do I need to install _globally_ or with sudo?
I want to use "caseless" but the Copyright phrase is not specified. Please update the Copyright phrase on the source code.
Please publish the latest version of caseless which switched to Apache 2 license and includes a license file! Thank you!
This is tripping global leak detection in mocha in any project using this module.
Caseless.prototype.get = function (name) {
name = name.toLowerCase()
var result, key
var headers = this.dict
Object.keys(headers).forEach(function (key) {
_key = key.toLowerCase()
if (name === _key) result = headers[key]
})
return result
}
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.