1
0
mirror of https://github.com/bigchaindb/js-bigchaindb-driver.git synced 2024-12-28 15:47:50 +01:00

Fix Content-Type issue

This commit is contained in:
vrde 2017-06-22 17:19:31 +02:00
parent f63a868bc9
commit 3d83083ee8
No known key found for this signature in database
GPG Key ID: 6581C7C39B3D397D
4 changed files with 19 additions and 4 deletions

View File

@ -68,7 +68,7 @@ const tx = driver.Transaction.makeCreateTransaction(
const txSigned = driver.Transaction.signTransaction(tx, alice.privateKey)
// Send the transaction off to BigchainDB
let conn = new driver.Connection(API_PATH, { 'Content-Type': 'application/json' })
let conn = new driver.Connection(API_PATH)
conn.postTransaction(txSigned)
.then(() => conn.getStatus(txSigned.id))
@ -120,7 +120,7 @@ conn.postTransaction(txSigned)
const txSigned = BigchainDB.Transaction.signTransaction(tx, alice.privateKey)
// Send the transaction off to BigchainDB
let conn = new BigchainDB.Connection(API_PATH, { 'Content-Type': 'application/json' })
let conn = new BigchainDB.Connection(API_PATH)
conn.postTransaction(txSigned)
.then(() => conn.getStatus(txSigned.id))

View File

@ -1,10 +1,19 @@
import request from '../request'
const HEADER_BLACKLIST = ['content-type']
export default class Connection {
constructor(path, headers) {
constructor(path, headers = {}) {
this.path = path
this.headers = headers
this.headers = Object.assign({}, headers)
Object.keys(headers).forEach(header => {
if (HEADER_BLACKLIST.includes(header.toLowerCase())) {
throw new Error(`Header ${header} is reserved and cannot be set.`)
}
})
}
getApiUrls(endpoint) {

View File

@ -24,6 +24,7 @@ export default function request(url, config = {}, onlyJsonResponse = true) {
'Content-Type': 'application/json'
})
}
if (!url) {
return Promise.reject(new Error('Request was not given a url.'))
}

View File

@ -308,3 +308,8 @@ test('Search transaction containing an asset', t => {
.then(({ id }) => conn.listTransactions(id))
.then(transactions => t.truthy(transactions.length === 1))
})
test('Content-Type cannot be set', t => {
t.throws(() => new Connection(API_PATH, { 'Content-Type': 'application/json' }), Error)
})