-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Try to use browser APIs in Node.js as much as possible, now that Node supports fetch(). This requires bumping our Node.js requirement to version 18.2.0 (fetch() is available since Node 18.0.0, but the dispatcher option needed by http-cookie-agent only since 18.2.0), so we can also drop the second GitHub Actions job. fetch.js is now the base implementation of both node.js and browser.js; fetch-node.js adds cookie support, while fetch-browser.js renames the user-agent header to api-user-agent because Chrome doesn’t care about web standards that clearly say user-agent is allowed to be set. Unfortunately, http-cookie-agent still requires undici to be installed even when it’s also built into Node, because Node doesn’t expose the necessary internals to use the dispatcher option mentioned above. Related to # 26 (though we don’t actually support file uploads yet) as well as # 25.
- Loading branch information
1 parent
df72fcc
commit 35a8ffe
Showing
13 changed files
with
147 additions
and
256 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
Node 16.0.0 | ||
Node 18.2.0 | ||
Chrome 63 | ||
ChromeAndroid 63 | ||
Firefox 60 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { FetchSession } from './fetch.js'; | ||
|
||
class FetchBrowserSession extends FetchSession { | ||
|
||
getFetchOptions( headers ) { | ||
const { 'user-agent': userAgent, ...otherHeaders } = headers; | ||
return { | ||
...super.getFetchOptions( headers ), | ||
headers: { | ||
...otherHeaders, | ||
'api-user-agent': userAgent, | ||
}, | ||
}; | ||
} | ||
|
||
} | ||
|
||
export { | ||
FetchBrowserSession, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { CookieAgent } from 'http-cookie-agent/undici'; | ||
import { CookieJar } from 'tough-cookie'; | ||
import { FetchSession } from './fetch.js'; | ||
|
||
class FetchNodeSession extends FetchSession { | ||
|
||
constructor( apiUrl, defaultParams = {}, defaultOptions = {} ) { | ||
super( apiUrl, defaultParams, defaultOptions ); | ||
|
||
this.agent = new CookieAgent( { | ||
cookies: { jar: new CookieJar() }, | ||
} ); | ||
} | ||
|
||
getFetchOptions( headers ) { | ||
return { | ||
...super.getFetchOptions( headers ), | ||
dispatcher: this.agent, | ||
}; | ||
} | ||
|
||
} | ||
|
||
export { | ||
FetchNodeSession, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.