Skip to content
This repository was archived by the owner on Feb 12, 2024. It is now read-only.

Commit 9d83fa3

Browse files
committed
HTTP API server: parsing query string as binary in pubsub publish
1 parent 97e619f commit 9d83fa3

File tree

3 files changed

+8
-4
lines changed

3 files changed

+8
-4
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@
9393
},
9494
"dependencies": {
9595
"async": "^2.6.0",
96+
"binary-querystring": "^0.1.1",
9697
"bl": "^1.2.1",
9798
"boom": "^7.1.1",
9899
"bs58": "^4.0.1",

src/http/api/resources/pubsub.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
const PassThrough = require('stream').PassThrough
44
const bs58 = require('bs58')
5+
const binaryQueryString = require('binary-querystring')
56

67
exports = module.exports
78

@@ -58,7 +59,9 @@ exports.publish = {
5859
handler: (request, reply) => {
5960
const arg = request.query.arg
6061
const topic = arg[0]
61-
const buf = arg[1]
62+
63+
const rawArgs = binaryQueryString(request.url.search)
64+
const buf = rawArgs.arg[1]
6265

6366
const ipfs = request.server.app.ipfs
6467

@@ -70,7 +73,7 @@ exports.publish = {
7073
return reply(new Error('Missing buf'))
7174
}
7275

73-
ipfs.pubsub.publish(topic, Buffer.from(String(buf)), (err) => {
76+
ipfs.pubsub.publish(topic, buf, (err) => {
7477
if (err) {
7578
return reply(new Error(`Failed to publish to topic ${topic}: ${err}`))
7679
}

test/interop/pubsub.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ describe('pubsub', function () {
8383
], done)
8484
})
8585
})
86-
86+
8787
describe('ascii data', () => {
8888
const data = Buffer.from('hello world')
8989

@@ -258,7 +258,7 @@ describe('pubsub', function () {
258258

259259
describe('binary data', () => {
260260
const data = Buffer.from('a36161636179656162830103056164a16466666666f400010203040506070809', 'hex')
261-
261+
262262
it('publish from Go, subscribe on Go', (done) => {
263263
const topic = 'pubsub-binary-go-go'
264264
let n = 0

0 commit comments

Comments
 (0)