Skip to content

Commit

Permalink
Moved stream creation into start method (163-2)
Browse files Browse the repository at this point in the history
  • Loading branch information
bmingles committed Nov 22, 2024
1 parent 1bf09cc commit fed1590
Showing 1 changed file with 13 additions and 22 deletions.
35 changes: 13 additions & 22 deletions src/dh/NodeHttp2gRPCTransport.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import http2 from 'node:http2';
import { grpc } from '@improbable-eng/grpc-web';
import { assertDefined } from '../util';

export class NodeHttp2gRPCTransport implements grpc.Transport {
static _sessionMap: Map<string, http2.ClientHttp2Session> = new Map();
Expand Down Expand Up @@ -41,7 +42,6 @@ export class NodeHttp2gRPCTransport implements grpc.Transport {

private readonly _options: grpc.TransportOptions;
private readonly _session: http2.ClientHttp2Session;
private _metadata: grpc.Metadata | null = null;
private _request: http2.ClientHttp2Stream | null = null;

_createRequest = (
Expand Down Expand Up @@ -90,43 +90,34 @@ export class NodeHttp2gRPCTransport implements grpc.Transport {
start(metadata: grpc.Metadata): void {
console.log('[NodeHttp2Transport] start', metadata.headersMap);

Check warning on line 91 in src/dh/NodeHttp2gRPCTransport.ts

View workflow job for this annotation

GitHub Actions / call-unit / unit

Unexpected console statement

if (this._metadata != null) {
if (this._request != null) {
throw new Error('start called more than once');
}

this._metadata = metadata;
}

sendMessage(msgBytes: Uint8Array): void {
console.log('[NodeHttp2Transport] sendMessage', msgBytes);

const headers: Record<string, string> = {};
this._metadata?.forEach((key, values) => {
metadata?.forEach((key, values) => {
headers[key] = values.join(', ');
});

if (
!this._options.methodDefinition.requestStream &&
!this._options.methodDefinition.responseStream
) {
// Disable chunked encoding for unary calls
headers['Content-Length'] = String(msgBytes.length);
}

const request = this._createRequest(headers);
this._request = this._createRequest(headers);
}

request.write(msgBytes);
this._request = request;
sendMessage(msgBytes: Uint8Array): void {
console.log('[NodeHttp2Transport] sendMessage', msgBytes);

Check warning on line 106 in src/dh/NodeHttp2gRPCTransport.ts

View workflow job for this annotation

GitHub Actions / call-unit / unit

Unexpected console statement
assertDefined(this._request, '_request');
this._request.write(msgBytes);
}

finishSend(): void {
console.log('[NodeHttp2Transport] finishSend');

Check warning on line 112 in src/dh/NodeHttp2gRPCTransport.ts

View workflow job for this annotation

GitHub Actions / call-unit / unit

Unexpected console statement
this._request!.end();
assertDefined(this._request, '_request');
this._request.end();
}

cancel(): void {
console.log('[NodeHttp2Transport] cancel');

Check warning on line 118 in src/dh/NodeHttp2gRPCTransport.ts

View workflow job for this annotation

GitHub Actions / call-unit / unit

Unexpected console statement
this._request!.close();
assertDefined(this._request, '_request');
this._request.close();
}

/**
Expand Down

0 comments on commit fed1590

Please sign in to comment.