1
0
mirror of https://github.com/bigchaindb/js-bigchaindb-driver.git synced 2024-11-22 09:46:58 +01:00

Merge pull request #59 from bigchaindb/remove-content-type-if-no-body

Fix Content-Type issue
This commit is contained in:
vrde 2017-06-23 14:53:43 +02:00 committed by GitHub
commit 288304624a
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)
})