diff --git a/README.md b/README.md index ec2e4838..b03b00e9 100644 --- a/README.md +++ b/README.md @@ -501,6 +501,7 @@ registry](https://www.iana.org/assignments/core-parameters/core-parameters.xhtml These are the defaults formats: ```js registerFormat('text/plain', 0) +registerFormat('text/plain; charset=utf-8', 0) registerFormat('application/link-format', 40) registerFormat('application/xml', 41) registerFormat('application/octet-stream', 42) diff --git a/lib/option_converter.js b/lib/option_converter.js index 08dcbad3..853bf3ea 100644 --- a/lib/option_converter.js +++ b/lib/option_converter.js @@ -118,6 +118,7 @@ module.exports.registerFormat = registerFormat // See https://www.iana.org/assignments/core-parameters/core-parameters.xhtml#content-formats // for a list of all registered content-formats registerFormat('text/plain', 0) +registerFormat('text/plain; charset=utf-8', 0) registerFormat('application/link-format', 40) registerFormat('application/xml', 41) registerFormat('application/octet-stream', 42) diff --git a/test/end-to-end.js b/test/end-to-end.js index 1679e789..8bf1628d 100644 --- a/test/end-to-end.js +++ b/test/end-to-end.js @@ -152,7 +152,7 @@ describe('end-to-end', function () { }) describe('formats', function () { - const formats = ['text/plain', 'application/link-format', + const formats = ['text/plain; charset=utf-8', 'application/link-format', 'application/xml', 'application/octet-stream', 'application/exi', 'application/json', 'application/cbor'] @@ -247,6 +247,19 @@ describe('end-to-end', function () { }) }) + it('should support the \'Content-Format\' text/plain', function (done) { + const req = coap.request('coap://localhost:' + port) + + req.setOption('Content-Format', 'text/plain') + req.end() + + server.once('request', function (req) { + expect(req.options[0].name).to.equal('Content-Format') + expect(req.options[0].value).to.equal('text/plain; charset=utf-8') + done() + }) + }) + it('should allow option \'Max-Age\'', function (done) { const req = coap.request('coap://localhost:' + port) diff --git a/test/request.js b/test/request.js index e49ada0e..227c972c 100644 --- a/test/request.js +++ b/test/request.js @@ -663,7 +663,7 @@ describe('request', function () { }) const formatsString = { - 'text/plain': Buffer.of(0), + 'text/plain; charset=utf-8': Buffer.of(0), 'application/link-format': Buffer.of(40), 'application/xml': Buffer.of(41), 'application/octet-stream': Buffer.of(42), diff --git a/test/server.js b/test/server.js index df48c6df..e9f4d259 100644 --- a/test/server.js +++ b/test/server.js @@ -286,7 +286,7 @@ describe('server', function () { }) const formatsString = { - 'text/plain': Buffer.of(0), + 'text/plain; charset=utf-8': Buffer.of(0), 'application/link-format': Buffer.of(40), 'application/xml': Buffer.of(41), 'application/octet-stream': Buffer.of(42), @@ -557,7 +557,7 @@ describe('server', function () { send(generate()) server.on('request', (req, res) => { - res.setOption('Content-Format', 'text/plain') + res.setOption('Content-Format', 'text/plain; charset=utf-8') res.end('42') }) diff --git a/test/share-socket.js b/test/share-socket.js index cfd502ab..ae135a6e 100644 --- a/test/share-socket.js +++ b/test/share-socket.js @@ -147,7 +147,7 @@ describe('share-socket', function () { }) describe('formats', function () { - const formats = ['text/plain', 'application/link-format', + const formats = ['text/plain; charset=utf-8', 'application/link-format', 'application/xml', 'application/octet-stream', 'application/exi', 'application/json', 'application/cbor']