mirror of
https://github.com/bigchaindb/js-bigchaindb-driver.git
synced 2024-11-22 09:46:58 +01:00
Fix Content-Type issue
This commit is contained in:
parent
f63a868bc9
commit
3d83083ee8
@ -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))
|
||||
|
@ -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) {
|
||||
|
@ -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.'))
|
||||
}
|
||||
|
@ -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)
|
||||
})
|
||||
|
Loading…
Reference in New Issue
Block a user