-
Notifications
You must be signed in to change notification settings - Fork 640
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
grpc-js-core: handle eos headers as trailers
- Loading branch information
Showing
4 changed files
with
125 additions
and
54 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
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,36 @@ | ||
import {CallStream} from './call-stream'; | ||
import {Channel} from './channel'; | ||
import {BaseFilter, Filter, FilterFactory} from './filter'; | ||
import {StatusObject} from './call-stream'; | ||
import {Status} from './constants'; | ||
|
||
export class MetadataStatusFilter extends BaseFilter implements Filter { | ||
async receiveTrailers(status: Promise<StatusObject>): Promise<StatusObject> { | ||
let { code, details, metadata } = await status; | ||
if (code !== Status.UNKNOWN) { | ||
// we already have a known status, so don't assign a new one. | ||
return { code, details, metadata }; | ||
} | ||
const metadataMap = metadata.getMap(); | ||
if (typeof metadataMap['grpc-status'] === 'string') { | ||
let receivedCode = Number(metadataMap['grpc-status']); | ||
if (receivedCode in Status) { | ||
code = receivedCode; | ||
} | ||
metadata.remove('grpc-status'); | ||
} | ||
if (typeof metadataMap['grpc-message'] === 'string') { | ||
details = decodeURI(metadataMap['grpc-message'] as string); | ||
metadata.remove('grpc-message'); | ||
} | ||
return { code, details, metadata }; | ||
} | ||
} | ||
|
||
export class MetadataStatusFilterFactory implements | ||
FilterFactory<MetadataStatusFilter> { | ||
constructor(private readonly channel: Channel) {} | ||
createFilter(callStream: CallStream): MetadataStatusFilter { | ||
return new MetadataStatusFilter(); | ||
} | ||
} |
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