Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add support for text/plain; charset=utf-8 #269

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
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', (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