Socket
Socket
Sign inDemoInstall

bent

Package Overview
Dependencies
3
Maintainers
1
Versions
66
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 7.0.7 to 7.1.0

2

package.json
{
"name": "bent",
"version": "7.0.7",
"version": "7.1.0",
"description": "Functional HTTP client for Node.js w/ async/await.",

@@ -5,0 +5,0 @@ "main": "src/nodejs.js",

'use strict'
/* global fetch */
/* global fetch, btoa, Headers */
const core = require('./core')

@@ -21,5 +21,10 @@

const mkrequest = (statusCodes, method, encoding, headers, baseurl) => async (_url, body, _headers = {}) => {
_url = baseurl + _url
const parsed = new URL(_url)
_url = baseurl + (_url || '')
let parsed = new URL(_url)
if (!headers) headers = {}
if (parsed.username) {
headers.Authorization = 'Basic ' + btoa(parsed.username + ':' + parsed.password)
parsed = new URL(parsed.protocol + '//' + parsed.host + parsed.pathname + parsed.search)
}
if (parsed.protocol !== 'https:' && parsed.protocol !== 'http:') {

@@ -37,3 +42,2 @@ throw new Error(`Unknown protocol, ${parsed.protocol}`)

body = JSON.stringify(body)
if (!headers) headers = {}
headers['Content-Type'] = 'application/json'

@@ -45,5 +49,5 @@ } else {

_headers = { ...(headers || {}), ..._headers }
_headers = new Headers({ ...(headers || {}), ..._headers })
const resp = await fetch(_url, { method, headers: _headers, body })
const resp = await fetch(parsed, { method, headers: _headers, body })
resp.statusCode = resp.status

@@ -50,0 +54,0 @@

@@ -62,3 +62,3 @@ 'use strict'

const mkrequest = (statusCodes, method, encoding, headers, baseurl) => (_url, body = null, _headers = {}) => {
_url = baseurl + _url
_url = baseurl + (_url || '')
const parsed = new URL(_url)

@@ -80,2 +80,5 @@ let h

}
if (parsed.username || parsed.password) {
request.auth = [parsed.username, parsed.password].join(':')
}
const c = caseless(request.headers)

@@ -82,0 +85,0 @@ if (encoding === 'json') {

@@ -140,2 +140,8 @@ /* globals atob, it */

test('auth', async () => {
const request = bent('https://test:pass@httpbin.org/basic-auth/test/pass', 'json')
const obj = await request()
same(obj, { authenticated: true, user: 'test' })
})
if (process.browser) {

@@ -142,0 +148,0 @@ test('override headers', async () => {

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc