Skip to content

Commit

Permalink
fix(Request): support custom "credentials" value
Browse files Browse the repository at this point in the history
  • Loading branch information
kettanaito committed Oct 12, 2022
1 parent a9203c7 commit 41c3bc3
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
4 changes: 3 additions & 1 deletion packages/fetch/src/request.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ const isRequest = object => {
* @property {string} method
* @property {RequestRedirect} redirect
* @property {globalThis.Headers} headers
* @property {RequestCredentials} credentials
* @property {URL} parsedURL
* @property {AbortSignal|null} signal
*
Expand Down Expand Up @@ -125,6 +126,7 @@ export default class Request extends Body {
method,
redirect: init.redirect || input.redirect || 'follow',
headers,
credentials: init.credentials || 'same-origin',
parsedURL,
signal: signal || null
};
Expand Down Expand Up @@ -159,7 +161,7 @@ export default class Request extends Body {
*/

get credentials() {
return "same-origin"
return this[INTERNALS].credentials
}

/**
Expand Down
10 changes: 10 additions & 0 deletions packages/fetch/test/request.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,16 @@ describe('Request', () => {
expect(clonedRequest.signal.aborted).to.equal(true);
});

it('should default to "same-origin" as credentials', () => {
const request = new Request(base)
expect(request.credentials).to.equal('same-origin');
})

it('should respect custom credentials value', () => {
expect(new Request(base, { credentials: 'omit'})).to.have.property('credentials', 'omit');
expect(new Request(base, { credentials: 'include'})).to.have.property('credentials', 'include');
})

it('should throw error with GET/HEAD requests with body', () => {
expect(() => new Request(base, {body: ''}))
.to.throw(TypeError);
Expand Down

0 comments on commit 41c3bc3

Please sign in to comment.