Skip to content
This repository has been archived by the owner on Apr 12, 2024. It is now read-only.

Commit

Permalink
fix: ReadableStream issue in Safari (#43)
Browse files Browse the repository at this point in the history
* fix: ReadableStream issue in Safari

- pass url & requestinit directly to httpclient

Close: #36

Signed-off-by: Deyan Valkanov <[email protected]>
Signed-off-by: Deyan Valkanov <[email protected]>

* Update review_uri to match the MR

Signed-off-by: Deyan Valkanov <[email protected]>
  • Loading branch information
valkanov authored May 10, 2021
1 parent 76a3bc9 commit a0becaa
Show file tree
Hide file tree
Showing 8 changed files with 134 additions and 116 deletions.
9 changes: 9 additions & 0 deletions build/npm/transport.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,15 @@
"license": "BSD-2-Clause",
"changelogHistory": [
{
"date": "5/10/21",
"version": "1.2.8",
"notes": [
{
"description": "Fix ReadableStream issue in Safari",
"review_uri": "https://github.com/vmware/transport-typescript/pull/43"
}
]
},{
"date": "2/11/21",
"version": "1.2.7",
"notes": [
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@vmw/transport",
"version": "1.2.7",
"version": "1.2.8",
"private": false,
"license": "BSD-2-Clause",
"repository": "[email protected]:vmware/transport-typescript.git",
Expand Down
2 changes: 1 addition & 1 deletion src/bus.api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { FabricApi } from './fabric.api';
import { BrokerConnector } from './bridge';

// current version
const version = '1.2.7';
const version = '1.2.8';

export type ChannelName = string;
export type SentFrom = string;
Expand Down
10 changes: 5 additions & 5 deletions src/core/services/rest/http.client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
*/

export interface HttpClient {
get(request: Request, successHandler: Function, failureHandler: Function): void;
post(request: Request, successHandler: Function, failureHandler: Function): void;
put(request: Request, successHandler: Function, failureHandler: Function): void;
patch(request: Request, successHandler: Function, failureHandler: Function): void;
delete(request: Request, successHandler: Function, failureHandler: Function): void;
get(uri: string, requestInit: RequestInit, successHandler: Function, failureHandler: Function): void;
post(uri: string, requestInit: RequestInit, successHandler: Function, failureHandler: Function): void;
put(uri: string, requestInit: RequestInit, successHandler: Function, failureHandler: Function): void;
patch(uri: string, requestInit: RequestInit, successHandler: Function, failureHandler: Function): void;
delete(uri: string, requestInit: RequestInit, successHandler: Function, failureHandler: Function): void;
}
24 changes: 12 additions & 12 deletions src/core/services/rest/httpclient.mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,28 +11,28 @@ export class MockHttpClient implements HttpClient {
public mustFail = false;
public errCode = 200;

delete(request: Request, successHandler: Function, failureHandler: Function): void {
this.httpOperation(request, successHandler, failureHandler);
delete(uri: string, requestInit: RequestInit, successHandler: Function, failureHandler: Function): void {
this.httpOperation(uri, requestInit, successHandler, failureHandler);
}

get(request: Request, successHandler: Function, failureHandler: Function): void {
this.httpOperation(request, successHandler, failureHandler);
get(uri: string, requestInit: RequestInit, successHandler: Function, failureHandler: Function): void {
this.httpOperation(uri, requestInit, successHandler, failureHandler);
}

patch(request: Request, successHandler: Function, failureHandler: Function): void {
this.httpOperation(request, successHandler, failureHandler);
patch(uri: string, requestInit: RequestInit, successHandler: Function, failureHandler: Function): void {
this.httpOperation(uri, requestInit, successHandler, failureHandler);
}

post(request: Request, successHandler: Function, failureHandler: Function): void {
this.httpOperation(request, successHandler, failureHandler);
post(uri: string, requestInit: RequestInit, successHandler: Function, failureHandler: Function): void {
this.httpOperation(uri, requestInit, successHandler, failureHandler);
}

put(request: Request, successHandler: Function, failureHandler: Function): void {
this.httpOperation(request, successHandler, failureHandler);
put(uri: string, requestInit: RequestInit, successHandler: Function, failureHandler: Function): void {
this.httpOperation(uri, requestInit, successHandler, failureHandler);
}

private httpOperation(
request: Request,
uri: string, requestInit: RequestInit,
successHandler: Function,
errorHandler: Function
) {
Expand All @@ -47,7 +47,7 @@ export class MockHttpClient implements HttpClient {
err['message'] = 'Fake Error';
errorHandler(err);
} else {
successHandler(`${request.method} called`);
successHandler(`${requestInit.method} called`);
}
}
}
33 changes: 9 additions & 24 deletions src/core/services/rest/rest.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,45 +187,30 @@ export class RestService extends AbstractCore implements EventBusEnabled, Fabric

// generate fetch headers, init and request objects.
const requestHeadersObject = new Headers(requestHeaders);
const requestInit = this.generateRequestInitObject(restObject, requestHeadersObject);
let httpRequest;
const requestInit: RequestInit = this.generateRequestInitObject(restObject, requestHeadersObject);

// try to create fetch request.
try {

const uri: string = this.globalBaseUri + restObject.uri;
this.log.debug(`Rest Service: Preparing Fetch Request for URI: ${uri}`, this.getName());
httpRequest = new Request(uri, requestInit);


} catch (e) {
this.log.error(`Rest Service: Cannot create request: ${e}`, this.getName());
this.handleError(
new RestError('Invalid HTTP request.', RestErrorType.UnknownMethod, restObject.uri),
restObject,
args);
return;
}
const uri: string = this.globalBaseUri + restObject.uri;
this.log.debug(`Rest Service: Preparing Fetch Request for URI: ${uri}`, this.getName());

switch (restObject.request) {
case HttpRequest.Get:
this.httpClient.get(httpRequest, successHandler, errorHandler);
this.httpClient.get(uri, requestInit, successHandler, errorHandler);
break;

case HttpRequest.Post:
this.httpClient.post(httpRequest, successHandler, errorHandler);
this.httpClient.post(uri, requestInit, successHandler, errorHandler);
break;

case HttpRequest.Patch:
this.httpClient.patch(httpRequest, successHandler, errorHandler);
this.httpClient.patch(uri, requestInit, successHandler, errorHandler);
break;

case HttpRequest.Put:
this.httpClient.put(httpRequest, successHandler, errorHandler);
this.httpClient.put(uri, requestInit, successHandler, errorHandler);
break;

case HttpRequest.Delete:
this.httpClient.delete(httpRequest, successHandler, errorHandler);
this.httpClient.delete(uri, requestInit, successHandler, errorHandler);
break;

default:
Expand All @@ -238,7 +223,7 @@ export class RestService extends AbstractCore implements EventBusEnabled, Fabric
}
}

private generateRequestInitObject(restObject: RestObject, headers: Headers): any {
private generateRequestInitObject(restObject: RestObject, headers: Headers): RequestInit {

let requestInit: any = {
method: restObject.request,
Expand Down
Loading

0 comments on commit a0becaa

Please sign in to comment.