Skip to content

Commit

Permalink
Merge pull request #789 from relu91/fix_785
Browse files Browse the repository at this point in the history
Fix writing property on browsers
  • Loading branch information
relu91 authored Jun 30, 2022
2 parents 33fa858 + 608cb84 commit fda5ae4
Show file tree
Hide file tree
Showing 10 changed files with 866 additions and 648 deletions.
483 changes: 252 additions & 231 deletions package-lock.json

Large diffs are not rendered by default.

5 changes: 4 additions & 1 deletion packages/binding-http/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@
],
"main": "dist/http.js",
"types": "dist/http.d.ts",
"browser": "dist/http-browser.js",
"browser": {
"./dist/http.js": "./dist/http-browser.js",
"./dist/http-client.js": "./dist/http-client-browser.js"
},
"devDependencies": {
"@testdeck/mocha": "^0.1.2",
"@types/accept-language-parser": "^1.5.2",
Expand Down
33 changes: 33 additions & 0 deletions packages/binding-http/src/http-client-browser.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/********************************************************************************
* Copyright (c) 2022 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0, or the W3C Software Notice and
* Document License (2015-05-13) which is available at
* https://www.w3.org/Consortium/Legal/2015/copyright-software-and-document.
*
* SPDX-License-Identifier: EPL-2.0 OR W3C-20150513
********************************************************************************/
import { ProtocolHelpers } from "@node-wot/core";
import { RequestInit, Request } from "node-fetch";
import { Readable } from "stream";
import { HttpForm, HTTPMethodName } from "./http";
import HttpClient from "./http-client-impl";

export default class BrowserHttpClient extends HttpClient {
protected async generateFetchRequest(
form: HttpForm,
defaultMethod: HTTPMethodName,
additionalOptions?: RequestInit
): Promise<Request> {
if (additionalOptions?.body instanceof Readable) {
const buffer = await ProtocolHelpers.readStreamFully(additionalOptions.body);
additionalOptions.body = buffer;
}
return super.generateFetchRequest(form, defaultMethod, additionalOptions);
}
}
Loading

0 comments on commit fda5ae4

Please sign in to comment.