Skip to content

Commit b6973c8

Browse files
committed
fixup! feat(coap-request): adapt to http-request
1 parent 0ae7fa5 commit b6973c8

File tree

2 files changed

+17
-8
lines changed

2 files changed

+17
-8
lines changed

coap/coap-request.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ module.exports = function (RED) {
6363
};
6464
reqOpts.method = config.method.toUpperCase() || "GET";
6565
if (config.method === "use" && msg.method != null) {
66-
reqOpts = msg.method.toUpperCase();
66+
reqOpts.method = msg.method.toUpperCase();
6767
}
6868

6969
reqOpts.headers = msg.headers;
@@ -98,7 +98,7 @@ module.exports = function (RED) {
9898
_send(data);
9999
} else if (contentFormat === "text/plain" || configContentFormat === "text/plain") {
100100
_send(data.toString());
101-
} else if (contentFormat.startsWith("application/") && contentFormat.endsWith("json")) {
101+
} else if (contentFormat.startsWith("application/") && contentFormat.includes("json")) {
102102
try {
103103
_send(JSON.parse(data.toString()));
104104
} catch (error) {
@@ -109,7 +109,7 @@ module.exports = function (RED) {
109109
});
110110
node.error(error.message);
111111
}
112-
} else if (contentFormat.startsWith("application/") && contentFormat.endsWith("cbor")) {
112+
} else if (contentFormat.startsWith("application/") && contentFormat.includes("cbor")) {
113113
cbor.decodeAll(data, function (error, data) {
114114
if (error) {
115115
node.error(error.message);
@@ -144,7 +144,7 @@ module.exports = function (RED) {
144144
var payload;
145145

146146
if (reqOpts.method !== "GET") {
147-
payload = _constructPayload(msg, config["content-format"]);
147+
payload = _constructPayload(msg, reqOpts.headers["Content-Format"]);
148148
} else if (paytoqs === "query") {
149149
try {
150150
_appendQueryParams(reqOpts, msg.payload);

test/coap-request_spec.js

+13-4
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ describe("CoapRequestNode", function () {
141141
id: "n3",
142142
type: "coap request",
143143
"content-format": "text/plain",
144-
method: "",
144+
method: "use",
145145
name: "coapRequest",
146146
observe: false,
147147
url: "coap://localhost:" + port + "/test-resource",
@@ -619,8 +619,18 @@ describe("CoapRequestNode", function () {
619619
id: "n1",
620620
type: "inject",
621621
name: "Fire once",
622-
payload: test.message,
623-
payloadType: "string",
622+
props: [
623+
{
624+
"p": "payload",
625+
"vt": "string",
626+
"v": test.message
627+
},
628+
{
629+
"p": "headers",
630+
"v": {"Content-Format": test.format},
631+
"vt": "object"
632+
}
633+
],
624634
repeat: "",
625635
crontab: "",
626636
once: true,
@@ -629,7 +639,6 @@ describe("CoapRequestNode", function () {
629639
{
630640
id: "n2",
631641
type: "coap request",
632-
"content-format": test.format,
633642
method: "POST",
634643
name: "coapRequestPost",
635644
observe: false,

0 commit comments

Comments
 (0)