Skip to content

Commit

Permalink
fix: add support for text/plain; charset=utf-8
Browse files Browse the repository at this point in the history
  • Loading branch information
JKRhb committed Sep 25, 2021
1 parent 8aa1b7c commit d8b9a14
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 5 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -500,6 +500,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)
Expand Down
1 change: 1 addition & 0 deletions lib/option_converter.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
15 changes: 14 additions & 1 deletion test/end-to-end.js
Original file line number Diff line number Diff line change
Expand Up @@ -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']

Expand Down Expand Up @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion test/request.js
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
4 changes: 2 additions & 2 deletions test/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -557,7 +557,7 @@ describe('server', function () {
send(generate())

server.on('request', function (req, res) {
res.setOption('Content-Format', 'text/plain')
res.setOption('Content-Format', 'text/plain; charset=utf-8')
res.end('42')
})

Expand Down
2 changes: 1 addition & 1 deletion test/share-socket.js
Original file line number Diff line number Diff line change
Expand Up @@ -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']

Expand Down

0 comments on commit d8b9a14

Please sign in to comment.