Skip to content

Commit

Permalink
fixup! feat(coap-request): adapt to http-request
Browse files Browse the repository at this point in the history
  • Loading branch information
JKRhb committed Sep 21, 2021
1 parent 0ae7fa5 commit b6973c8
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
8 changes: 4 additions & 4 deletions coap/coap-request.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ module.exports = function (RED) {
};
reqOpts.method = config.method.toUpperCase() || "GET";
if (config.method === "use" && msg.method != null) {
reqOpts = msg.method.toUpperCase();
reqOpts.method = msg.method.toUpperCase();
}

reqOpts.headers = msg.headers;
Expand Down Expand Up @@ -98,7 +98,7 @@ module.exports = function (RED) {
_send(data);
} else if (contentFormat === "text/plain" || configContentFormat === "text/plain") {
_send(data.toString());
} else if (contentFormat.startsWith("application/") && contentFormat.endsWith("json")) {
} else if (contentFormat.startsWith("application/") && contentFormat.includes("json")) {
try {
_send(JSON.parse(data.toString()));
} catch (error) {
Expand All @@ -109,7 +109,7 @@ module.exports = function (RED) {
});
node.error(error.message);
}
} else if (contentFormat.startsWith("application/") && contentFormat.endsWith("cbor")) {
} else if (contentFormat.startsWith("application/") && contentFormat.includes("cbor")) {
cbor.decodeAll(data, function (error, data) {
if (error) {
node.error(error.message);
Expand Down Expand Up @@ -144,7 +144,7 @@ module.exports = function (RED) {
var payload;

if (reqOpts.method !== "GET") {
payload = _constructPayload(msg, config["content-format"]);
payload = _constructPayload(msg, reqOpts.headers["Content-Format"]);
} else if (paytoqs === "query") {
try {
_appendQueryParams(reqOpts, msg.payload);
Expand Down
17 changes: 13 additions & 4 deletions test/coap-request_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ describe("CoapRequestNode", function () {
id: "n3",
type: "coap request",
"content-format": "text/plain",
method: "",
method: "use",
name: "coapRequest",
observe: false,
url: "coap://localhost:" + port + "/test-resource",
Expand Down Expand Up @@ -619,8 +619,18 @@ describe("CoapRequestNode", function () {
id: "n1",
type: "inject",
name: "Fire once",
payload: test.message,
payloadType: "string",
props: [
{
"p": "payload",
"vt": "string",
"v": test.message
},
{
"p": "headers",
"v": {"Content-Format": test.format},
"vt": "object"
}
],
repeat: "",
crontab: "",
once: true,
Expand All @@ -629,7 +639,6 @@ describe("CoapRequestNode", function () {
{
id: "n2",
type: "coap request",
"content-format": test.format,
method: "POST",
name: "coapRequestPost",
observe: false,
Expand Down

0 comments on commit b6973c8

Please sign in to comment.