Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@node-wot/binding-http

Package Overview
Dependencies
Maintainers
4
Versions
42
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@node-wot/binding-http - npm Package Compare versions

Comparing version 0.8.3 to 0.8.4

4

dist/http-client-impl.js

@@ -121,3 +121,5 @@ "use strict";

this.activeSubscriptions.set(form.href, internalSubscription);
resolve(new Subscription_1.Subscription(null));
resolve(new Subscription_1.Subscription(() => {
internalSubscription.close();
}));
})

@@ -124,0 +126,0 @@ .catch((err) => reject(err));

@@ -35,2 +35,4 @@ /// <reference types="node" />

private fillSecurityScheme;
private negotiateLanguage;
private handleTdRequest;
private handleRequest;

@@ -37,0 +39,0 @@ private isEmpty;

@@ -263,2 +263,3 @@ "use strict";

addEndpoint(thing, tdTemplate, base) {
var _a, _b, _c;
for (const type of core_1.ContentSerdes.get().getOfferedMediaTypes()) {

@@ -304,3 +305,3 @@ let allReadOnly = true;

const form = new TD.Form(href, type);
core_1.ProtocolHelpers.updatePropertyFormWithTemplate(form, thing.properties[propertyName]);
core_1.ProtocolHelpers.updatePropertyFormWithTemplate(form, ((_a = tdTemplate === null || tdTemplate === void 0 ? void 0 : tdTemplate.properties[propertyName]) !== null && _a !== void 0 ? _a : {}));
if (thing.properties[propertyName].readOnly) {

@@ -346,3 +347,3 @@ form.op = ["readproperty"];

const form = new TD.Form(href, type);
core_1.ProtocolHelpers.updateActionFormWithTemplate(form, thing.actions[actionName]);
core_1.ProtocolHelpers.updateActionFormWithTemplate(form, ((_b = tdTemplate === null || tdTemplate === void 0 ? void 0 : tdTemplate.actions[actionName]) !== null && _b !== void 0 ? _b : {}));
form.op = ["invokeaction"];

@@ -361,3 +362,3 @@ const hform = form;

const form = new TD.Form(href, type);
core_1.ProtocolHelpers.updateEventFormWithTemplate(form, thing.events[eventName]);
core_1.ProtocolHelpers.updateEventFormWithTemplate(form, ((_c = tdTemplate === null || tdTemplate === void 0 ? void 0 : tdTemplate.events[eventName]) !== null && _c !== void 0 ? _c : {}));
form.subprotocol = "longpoll";

@@ -439,2 +440,48 @@ form.op = ["subscribeevent", "unsubscribeevent"];

}
negotiateLanguage(td, thing, req) {
if (req.headers["accept-language"] && req.headers["accept-language"] !== "*") {
if (thing.titles) {
const supportedLanguages = Object.keys(thing.titles);
const prefLang = acceptLanguageParser.pick(supportedLanguages, req.headers["accept-language"], {
loose: true,
});
if (prefLang) {
debug(`TD language negotiation through the Accept-Language header field of HTTP leads to "${prefLang}"`);
this.resetMultiLangThing(td, prefLang);
}
}
}
}
handleTdRequest(thing, req, res) {
var _a, _b;
return __awaiter(this, void 0, void 0, function* () {
const td = thing.getThingDescription();
const contentSerdes = core_1.ContentSerdes.get();
const acceptValues = (_b = (_a = req.headers.accept) === null || _a === void 0 ? void 0 : _a.split(",").map((acceptValue) => acceptValue.split(";")[0])) !== null && _b !== void 0 ? _b : [
core_1.ContentSerdes.TD,
];
const filteredAcceptValues = acceptValues
.map((acceptValue) => {
if (acceptValue === "*/*") {
return core_1.ContentSerdes.TD;
}
return acceptValue;
})
.filter((acceptValue) => contentSerdes.isSupported(acceptValue));
if (filteredAcceptValues.length > 0) {
const contentType = filteredAcceptValues[0];
const content = contentSerdes.valueToContent(thing.getThingDescription(), undefined, contentType);
const payload = yield content.toBuffer();
this.negotiateLanguage(td, thing, req);
res.setHeader("Content-Type", contentType);
res.writeHead(200);
debug(`Sending HTTP response for TD with Content-Type ${contentType}.`);
res.end(payload);
return;
}
debug(`Request contained an accept header with the values ${acceptValues}, none of which are supported.`);
res.writeHead(406);
res.end(`Accept header contained no Content-Types supported by this resource. (Was ${acceptValues})`);
});
}
handleRequest(req, res) {

@@ -527,19 +574,3 @@ return __awaiter(this, void 0, void 0, function* () {

if (req.method === "GET") {
const td = thing.getThingDescription();
if (req.headers["accept-language"] && req.headers["accept-language"] !== "*") {
if (thing.titles) {
const supportedLanguagesArray = [];
for (const lang in thing.titles) {
supportedLanguagesArray.push(lang);
}
const prefLang = acceptLanguageParser.pick(supportedLanguagesArray, req.headers["accept-language"], { loose: true });
if (prefLang) {
debug(`TD language negotiation through the Accept-Language header field of HTTP leads to "${prefLang}"`);
this.resetMultiLangThing(td, prefLang);
}
}
}
res.setHeader("Content-Type", core_1.ContentSerdes.TD);
res.writeHead(200);
res.end(JSON.stringify(td));
this.handleTdRequest(thing, req, res);
}

@@ -546,0 +577,0 @@ else {

{
"name": "@node-wot/binding-http",
"version": "0.8.3",
"version": "0.8.4",
"description": "HTTP client & server protocol binding for node-wot",

@@ -55,4 +55,4 @@ "author": "Eclipse Thingweb <thingweb-dev@eclipse.org> (https://thingweb.io/)",

"dependencies": {
"@node-wot/core": "0.8.3",
"@node-wot/td-tools": "0.8.3",
"@node-wot/core": "0.8.4",
"@node-wot/td-tools": "0.8.4",
"@types/eventsource": "^1.1.2",

@@ -59,0 +59,0 @@ "accept-language-parser": "1.5.0",

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc