Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ember-Data 3.9.1 adapter "headers" seems to be not getting sent. #6058

Closed
nikhilsane opened this issue Apr 23, 2019 · 7 comments · Fixed by #6062
Closed

Ember-Data 3.9.1 adapter "headers" seems to be not getting sent. #6058

nikhilsane opened this issue Apr 23, 2019 · 7 comments · Fixed by #6062
Labels
🏷️ bug This PR primarily fixes a reported issue

Comments

@nikhilsane
Copy link
Contributor

Ember-Data 3.9.1 JSONAPIAdapter does not seem to send headers.

Hi Ember-Data team,

I have following Adapter in my application:

export default DS.JSONAPIAdapter.extend({
    namespace: '/foo/resources/v2.0',
    init() {
        this._super(...arguments);

        this.set('headers', {
            'Accept': 'application/json',
            'ApplicationQuery': '1'
        })
    }
});

When using v3.9.1, the "findAll" query sends the following header in the request:

Request headers:
Host: localhost:9000
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:66.0) Gecko/20100101 Firefox/66.0
Accept: application/vnd.api+json
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate
Content-Type: application/vnd.api+json
ApplicationQuery: 1
X-Requested-With: XMLHttpRequest
Connection: keep-alive
Cookie: JSESSIONID=02E588F5129EFD7540B86F6F526D2371

When using v3.5.1, the "findAll" query that is sent to the back-end API looks like the following:

Request headers:
Host: localhost:9000
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:66.0) Gecko/20100101 Firefox/66.0
Accept: application/json
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate
X-Requested-With: XMLHttpRequest
Connection: keep-alive
Cookie: JSESSIONID=487615003A26F1141D0F22B9354F409B

So, as can be seen from the above outputs, the same code does not seem to work in v 3.9.1. Is this expected behavior? Am I missing something here?

Versions

Following are the versions of the packages: ember-source, ember-cli, ember-data

`-- ember-source@3.7.0
`-- ember-cli@3.1.4
`-- ember-data@3.9.1

Thanks,

Nikhil.

@runspired
Copy link
Contributor

Hi Nikhil,

This does appear to be a regression. This line here needs to be changed to the following

options.contentType = options.contentType || 'application/vnd.api+json';

If you could submit a PR with this fix and a test that would be greatly appreciated :)

@nikhilsane
Copy link
Contributor Author

Hi Chris,

Thanks for pointing me to the code line causing this issue. I have made the change, and now trying to push my local branch to the repository, but I am getting following error:

remote: Permission to emberjs/data.git denied to nikhilsane.
fatal: unable to access 'https://github.com/emberjs/data.git/': The requested URL returned error: 403

Seems like I do not have permissions to submit to this repo.

thanks,
nikhil.

@runspired
Copy link
Contributor

@nikhilsane generally you would fork the repo, push to your own fork, and PR from your fork to this repository. Happy to help you learn how to do so if you are not familiar with that process :)

@nikhilsane
Copy link
Contributor Author

@runspired : Thanks for the information. I have created a pull request from a fork. Please let me know if there is something missing.

Thanks,

@rwjblue
Copy link
Member

rwjblue commented May 1, 2019

@runspired

hash.headers['Accept'] = 'application/vnd.api+json';
is also an issue, we cannot assume to force Accept like this

Consider:

  headers: computed(function() {
    return {
      'Content-Type': 'application/vnd.api+json; version=1',
      'Accept': 'application/vnd.api+json; version=1'
    }
  }),

@runspired
Copy link
Contributor

@rwjblue that was already noted in the PR discussion, but thanks :)

@eluciano11
Copy link

Hi ember-data team,

First of all, thank you for your work!

I'm writing because I found an issue on the ajaxOptions methods as well.

Issue

The issue that I'm seeing is the following:
Error while processing route: two-factor-auth Cannot read property 'contentType' of null TypeError: Cannot read property 'contentType' of null

It seems like the ajaxOptions is receiving null as an argument and the object that's being used as the function default param is not being applied.

Example:
Screen Shot 2019-08-13 at 11 11 20 AM

I've confirmed that this is happening on ember-data version greater than 3.9.0.

Versions

"ember-source": "~3.11.1",
"ember-data": "3.11.4",

@runspired runspired added 🏷️ bug This PR primarily fixes a reported issue and removed Bug labels Sep 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🏷️ bug This PR primarily fixes a reported issue
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants