feat(headers): add functions to remove and get extra headers by Haroenv · Pull Request #572 · algolia/algoliasearch-client-javascript · GitHub
Skip to content

feat(headers): add functions to remove and get extra headers#572

Merged
Haroenv merged 1 commit into
developfrom
feat/remove-get-extra-header
Jul 20, 2017
Merged

feat(headers): add functions to remove and get extra headers#572
Haroenv merged 1 commit into
developfrom
feat/remove-get-extra-header

Conversation

@Haroenv

@Haroenv Haroenv commented Jul 18, 2017

Copy link
Copy Markdown
Contributor

Summary

There's no way to check an extra header or remove one, so that needed to be done

Result

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

closes #571

@Haroenv Haroenv requested a review from vvo July 18, 2017 09:41

@Haroenv Haroenv Jul 18, 2017

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I sorted them alphabetically, since that seemed to be what they used to be sorted in once

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call :)


test('client.setExtraHeader(key, value)', function(t) {
t.plan(4);
t.plan(11);

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know why this was originally 4 since there were already 6 tests

@Haroenv

Haroenv commented Jul 18, 2017

Copy link
Copy Markdown
Contributor Author

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

@Haroenv Haroenv force-pushed the feat/remove-get-extra-header branch 4 times, most recently from 7eda5db to 2296f9c Compare July 18, 2017 10:14

@bobylito bobylito left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Comment thread src/AlgoliaSearchCore.js Outdated
*
* @param name the header field name
*/
AlgoliaSearchCore.prototype.deleteExtraHeader = function(name) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wondering about delete vs unset (since we use set), any arguments?

Comment thread src/AlgoliaSearchCore.js Outdated
return params;
};

// jQuery's version of isEmpty

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you put a link to the source? with proper sha and maybe copyright

Comment thread src/AlgoliaSearchCore.js Outdated
if (this.extraHeaders) {
forEach(this.extraHeaders, function addToRequestHeaders(header) {
requestHeaders[header.name] = header.value;
if (!isEmpty(this.extraHeaders)) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would have used object keys but it's not available in IE8 :)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately, I thought the same 😭

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great call ❤️

@vvo

vvo commented Jul 18, 2017

Copy link
Copy Markdown

Do I need to add more documentation for this somewhere?

Maybe, check doc repository and search for setExtraHeader

@Haroenv Haroenv force-pushed the feat/remove-get-extra-header branch 2 times, most recently from 7bc72a3 to acf38d2 Compare July 18, 2017 15:03
@Haroenv Haroenv requested a review from vvo July 18, 2017 15:04
@Haroenv

Haroenv commented Jul 19, 2017

Copy link
Copy Markdown
Contributor Author

setExtraHeader is not documented, so there’s no need to add documentation for these methods either 😄

```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
@Haroenv Haroenv force-pushed the feat/remove-get-extra-header branch from acf38d2 to 86ef097 Compare July 20, 2017 09:30
@Haroenv

Haroenv commented Jul 20, 2017

Copy link
Copy Markdown
Contributor Author

@Haroenv Haroenv merged commit 0271935 into develop Jul 20, 2017
@Haroenv Haroenv deleted the feat/remove-get-extra-header branch July 20, 2017 09:42
Haroenv added a commit that referenced this pull request Jul 20, 2017
* 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

No way to add and remove headers

3 participants