feat(http): add config parameter to headers functions #7235

Closed
wants to merge 1 commit into
from
@grisendo

Request Type: feature

How to reproduce:

Component(s): $http

Impact:

Complexity: small

This issue is related to:

Detailed Description:

Adds 'data' parameter in $http's header property when headers defined as functions

Other Comments:

This pull request adds to $http header functions a data parameter, so headers can use object properties to be built:

Example (in a $resource) :

...
                  login: {
                    url: './api/login.json',
                    method: 'POST',
                    headers : {
                        'Authorization': function(data) {
                          return 'Basic ' + btoa(data.user + ':' + data.pass);
                        }
                    },
...
@mary-poppins

Thanks for the PR! Please check the items below to help us merge this faster. See the contributing docs for more information.

  • Uses the issue template (#7235)

If you need to make changes to your pull request, you can update the commit with git commit --amend.
Then, update the pull request with git push -f.

Thanks again for your help!

@lefos987 lefos987 added this to the Backlog milestone Apr 24, 2014
@mary-poppins

I'm sorry, but I wasn't able to verify your Contributor License Agreement (CLA) signature. CLA signature is required for any code contributions to AngularJS.

Please sign our CLA and ensure that the CLA signature email address and the email address in this PR's commits match.

If you signed the CLA as a corporation, please let us know the company's name.

Thanks a bunch!

PS: If you signed the CLA in the past then most likely the email addresses don't match. Please sign the CLA again or update the email address in the commit of this PR.
PS2: If you are a Googler, please sign the CLA as well to simplify the CLA verification process.

@grisendo grisendo added cla: no and removed cla: yes labels May 2, 2014
@mary-poppins

CLA signature verified! Thank you!

Someone from the team will now triage your PR and it will be processed based on the determined priority (doc updates and fixes with tests are prioritized over other changes).

@grisendo grisendo added cla: yes and removed cla: no labels May 2, 2014
@IgorMinar
Member

it might be better to pass in the config object since that one contains all of the information about the request. (other people might want to set a header depending on the http method or other header value)

we'll also need tests for this change.

@grisendo grisendo changed the title from feat(http): add data parameter to headers functions to feat(http): add config parameter to headers functions May 3, 2014
@grisendo
grisendo commented May 3, 2014

So now the example should be:

...
                  login: {
                    url: './api/login.json',
                    method: 'POST',
                    headers : {
                        'Authorization': function(config) {
                          return 'Basic ' + btoa(config.data.user + ':' + config.data.pass);
                        }
                    },
...
@btford btford removed the gh: PR label Aug 20, 2014
@pkozlowski-opensource

@grisendo - I think that this is a reasonable request and I can see that you've already incorporated Igor's suggestion. This PR could land but it requires a bit more work before it can be merged:

  • - it doesn't merge cleanly any more, could you please rebase it on top of the current master?
  • - we need to update docs to reflect this new argument

Thnx!

@grisendo

Just refactored, adding documentation later

@grisendo

Added also documentation changes.

@grisendo

Changed to 'config object' as @pkozlowski-opensource suggested and fixed a typo.

@pkozlowski-opensource

I'm not sure if 'data' is the best argument name here... What about configObj or something along those lines?

@grisendo
grisendo commented Sep 6, 2014

What about 'requestConfig', since is the name given to 'function $http(requestConfig) {' in 'src/ng/http.js' line 619?

@pkozlowski-opensource pkozlowski-opensource self-assigned this Nov 25, 2014
@pkozlowski-opensource pkozlowski-opensource modified the milestone: Backlog, 1.3.8 Dec 13, 2014
@btford btford modified the milestone: 1.3.8, 1.3.9 Dec 19, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment