-
Notifications
You must be signed in to change notification settings - Fork 436
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
Configurable Transports and Extraction of the Node HTTP Transport #265
Merged
Merged
Changes from 2 commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
fbebb1f
WIP to allow configuration of Transports.
jonny-improbable dcda21d
Fix linting
jonny-improbable 0774e58
Allow independent configuration of XHR and Fetch Transports.
jonny-improbable 17066a9
Fix lint
jonny-improbable dbf695b
Allow the user to specify the default transport.
jonny-improbable f3d41e7
Refactor transport package
jonny-improbable b08e5a8
Drop support for NodeJS transports.
jonny-improbable f35d8de
Allow extended configuration of FetchInit
jonny-improbable 84e10ba
Add support for referrerPolicy, keepalive and integrity FetchInit opt…
jonny-improbable e671411
Remove NodeJS typings as they are no longer required.
jonny-improbable a0cab8f
Rename `HttpTransport` -> `CrossBrowserHttpTransport` to make it clea…
jonny-improbable 3f668d7
Merge branch 'master' into feature/configurable-transports
jonny-improbable dbe3fbd
Move Node HTTP transport into the repo and include it in the tests.
jonny-improbable afc8caf
Fix linking script
jonny-improbable b5c274b
Fix linking
jonny-improbable ee85f3c
Trying to get linking working on travis...
jonny-improbable 86b3a6f
Give up on using npm link :D
jonny-improbable ebcb001
Revert "Give up on using npm link :D"
jonny-improbable bf08173
Make NPM Linking work after praying to the correct gods.
jonny-improbable 26b0c07
Remove duplicate call to `link-npm-modules.sh`
jonny-improbable 43ab1e9
- Reinstate note on NodeJS usage in README
jonny-improbable ca16ed5
Rewrite transport docs.
jonny-improbable d66c8af
Fix style issues.
jonny-improbable File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
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 |
---|---|---|
|
@@ -14,8 +14,8 @@ export interface Transport { | |
start(metadata: Metadata): void | ||
} | ||
|
||
export interface TransportConstructor { | ||
(options: TransportOptions): Transport | Error; | ||
export interface HttpTransportConstructor { | ||
(options: TransportOptions, config: HttpTransportConfig): Transport; | ||
} | ||
|
||
export interface TransportOptions { | ||
|
@@ -27,21 +27,11 @@ export interface TransportOptions { | |
onEnd: (err?: Error) => void; | ||
} | ||
|
||
let selectedTransport: TransportConstructor; | ||
export function DefaultTransportFactory(transportOptions: TransportOptions): Transport | Error { | ||
// The transports provided by DefaultTransportFactory do not support client-streaming | ||
if (transportOptions.methodDefinition.requestStream) { | ||
return new Error("No transport available for client-streaming (requestStream) method"); | ||
} | ||
|
||
if (!selectedTransport) { | ||
selectedTransport = detectTransport(); | ||
} | ||
|
||
return selectedTransport(transportOptions); | ||
export function DefaultHttpTransport(transportOptions: TransportOptions): Transport { | ||
return HttpTransport({ credentials: "same-origin" })(transportOptions); | ||
} | ||
|
||
function detectTransport(): TransportConstructor { | ||
function detectHttpTransport(): HttpTransportConstructor { | ||
if (detectFetchSupport()) { | ||
return fetchRequest; | ||
} | ||
|
@@ -61,6 +51,26 @@ function detectTransport(): TransportConstructor { | |
throw new Error("No suitable transport found for gRPC-Web"); | ||
} | ||
|
||
export function WebsocketTransportFactory(transportOptions: TransportOptions): Transport | Error { | ||
return websocketRequest(transportOptions); | ||
export interface HttpTransportConfig { | ||
credentials: "include" | "same-origin" | ||
} | ||
|
||
export interface TransportFactory { | ||
(options: TransportOptions): Transport; | ||
} | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When you view this file it's easy to notice a lot of empty lines - we should probably clean them up. |
||
export function HttpTransport(cfg: HttpTransportConfig): TransportFactory { | ||
let detectedTransport: HttpTransportConstructor | null = null; | ||
return (opts: TransportOptions) => { | ||
if (detectedTransport === null) { | ||
detectedTransport = detectHttpTransport(); | ||
} | ||
return detectedTransport(opts, cfg); | ||
} | ||
} | ||
|
||
export function WebsocketTransport(): TransportFactory { | ||
return (opts: TransportOptions) => { | ||
return websocketRequest(opts); | ||
} | ||
} |
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unrelated change, but whilst I was here I wanted to fix this.