feat(headers): add functions to remove and get extra headers#572
Conversation
There was a problem hiding this comment.
I sorted them alphabetically, since that seemed to be what they used to be sorted in once
|
|
||
| test('client.setExtraHeader(key, value)', function(t) { | ||
| t.plan(4); | ||
| t.plan(11); |
There was a problem hiding this comment.
I don't know why this was originally 4 since there were already 6 tests
|
As noted in rfc7230, rfc2616 and Stack Overflow you can't really have multiple headers with the same name, if that's the case, you should send an array, instead of calling setExtraHeader multiple times |
7eda5db to
2296f9c
Compare
| * | ||
| * @param name the header field name | ||
| */ | ||
| AlgoliaSearchCore.prototype.deleteExtraHeader = function(name) { |
There was a problem hiding this comment.
Wondering about delete vs unset (since we use set), any arguments?
| return params; | ||
| }; | ||
|
|
||
| // jQuery's version of isEmpty |
There was a problem hiding this comment.
Can you put a link to the source? with proper sha and maybe copyright
| if (this.extraHeaders) { | ||
| forEach(this.extraHeaders, function addToRequestHeaders(header) { | ||
| requestHeaders[header.name] = header.value; | ||
| if (!isEmpty(this.extraHeaders)) { |
There was a problem hiding this comment.
Would have used object keys but it's not available in IE8 :)
There was a problem hiding this comment.
Unfortunately, I thought the same 😭
There was a problem hiding this comment.
In the end, we do not even need to check isEmpty or not, since the forEach will not iterate on it if it has no properties, let's remove this code?
Maybe, check doc repository and search for setExtraHeader |
7bc72a3 to
acf38d2
Compare
|
|
```js
client.setExtraHeader('X-cool-header','hello there');
client.getExtraHeader('X-cool-header'); //hello there
client.deleteExtraHeader('X-cool-header');
client.getExtraHeader('X-cool-header'); //undefined
```
Do I need to add more documentation for this somewhere?
cc @alexandremeunier @vvo
acf38d2 to
86ef097
Compare
* feat(headers): add functions to remove and get extra headers (#572) * client.setExtraHeader('X-cool-header','hello there'); * client.getExtraHeader('X-cool-header'); //hello there * client.unsetExtraHeader('X-cool-header'); * client.getExtraHeader('X-cool-header'); //undefined * feat(deprecation): use console.warn to be more visible * refact(rules): Adapt to latest JSON schema for Query Rules

Summary
There's no way to check an extra header or remove one, so that needed to be done
Result
Do I need to add more documentation for this somewhere?
cc @alexandremeunier
closes #571