Skip to content

Commit

Permalink
Add ClientOptions class
Browse files Browse the repository at this point in the history
  • Loading branch information
stanley-cheung committed Oct 12, 2020
1 parent 83cb040 commit 44f479b
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 5 deletions.
12 changes: 12 additions & 0 deletions javascript/net/grpc/web/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,17 @@ closure_js_library(
visibility = ["//visibility:public"],
)

closure_js_library(
name = "clientoptions",
srcs = [
"clientoptions.js",
],
visibility = ["//visibility:public"],
deps = [
":interceptor",
],
)

closure_js_library(
name = "clientreadablestream",
srcs = [
Expand Down Expand Up @@ -106,6 +117,7 @@ closure_js_library(
visibility = ["//visibility:public"],
deps = [
":abstractclientbase",
":clientoptions",
":clientreadablestream",
":clientunarycallimpl",
":error",
Expand Down
50 changes: 50 additions & 0 deletions javascript/net/grpc/web/clientoptions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
goog.module('grpc.web.ClientOptions');
goog.module.declareLegacyNamespace();

const {StreamInterceptor, UnaryInterceptor} = goog.require('grpc.web.Interceptor');


/**
* Options that are availavle during the client construction.
* @record
*/
class ClientOptions {
constructor() {
/**
* Whether to use the HttpCors library to pack http headers into a special
* url query param $httpHeaders= so that browsers can bypass CORS OPTIONS
* requests.
* @type {boolean|undefined}
*/
this.suppressCorsPreflight;

/**
* Whether to turn on XMLHttpRequest's withCredentials flag.
* @type {boolean|undefined}
*/
this.withCredentials;

/**
* Unary interceptors. Note that they are only available in grpcweb and
* grpcwebtext mode
* @type {!Array<!UnaryInterceptor>|undefined}
*/
this.unaryInterceptors;

/**
* Stream interceptors. Note that they are only available in grpcweb and
* grpcwebtext mode
* @type {!Array<!StreamInterceptor>|undefined}
*/
this.streamInterceptors;

/**
* Protocol buffer format for open source gRPC-Web. This attribute should be
* specified by the gRPC-Web build rule by default.
* @type {string|undefined}
*/
this.format;
}
}

exports = ClientOptions;
5 changes: 3 additions & 2 deletions javascript/net/grpc/web/grpcwebclientbase.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ goog.module.declareLegacyNamespace();


const AbstractClientBase = goog.require('grpc.web.AbstractClientBase');
const ClientOptions = goog.requireType('grpc.web.ClientOptions');
const ClientReadableStream = goog.require('grpc.web.ClientReadableStream');
const ClientUnaryCallImpl = goog.require('grpc.web.ClientUnaryCallImpl');
const Error = goog.require('grpc.web.Error');
Expand All @@ -52,9 +53,9 @@ const {StreamInterceptor, UnaryInterceptor} = goog.require('grpc.web.Interceptor
*/
class GrpcWebClientBase {
/**
* @param {?Object=} options
* @param {!ClientOptions=} options
*/
constructor(options) {
constructor(options = {}) {
/**
* @const
* @private {string}
Expand Down
6 changes: 3 additions & 3 deletions javascript/net/grpc/web/streambodyclientreadablestream.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,11 +144,11 @@ class StreamBodyClientReadableStream {
if (grpcStatus == StatusCode.OK) {
this.sendDataCallbacks_(responseMessage);
} else {
callback(
this.sendErrorCallbacks_(
/** @type {!GrpcWebError} */ ({
code: grpcStatus,
}),
responseMessage);
message: response,
}));
}
} else {
let rawResponse;
Expand Down

0 comments on commit 44f479b

Please sign in to comment.