Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// some providers return wrong `content-type` like: text/html or text/plain
else {
try {
body = JSON.parse(body)
}
catch (err) {
// use qs instead of querystring for nested objects
body = qs.parse(body)
}
}
return {options, res, body, raw}
}
module.exports = require('request-compose').extend({
Request: {oauth: require('request-oauth')},
Response: {parse}
}).client
var express = require('express')
var session = require('express-session')
var grant = require('grant-express')
var request = require('request-compose').client
var jwt = require('./jwt')
express()
.use(session({name: 'grant', secret: 'grant', saveUninitialized: true, resave: true}))
.use(grant(require('./config.json')))
.get('/hello', async (req, res) => {
var {body} = await request({
url: 'https://graph.facebook.com/v2.12/me',
headers: {authorization: `Bearer ${req.session.grant.response.access_token}`}
})
// remove the session data
req.session.destroy(() => {
// remove the cookie
res.clearCookie('grant')
var t = require('assert')
var request = require('request-compose').extend({
Request: {cookie: require('request-cookie').Request},
Response: {cookie: require('request-cookie').Response},
}).client
var hapi = parseInt(require('hapi/package.json').version.split('.')[0])
var port = {auth: 5000, app: 5001}
var url = {
auth: (path) => `http://localhost:${port.auth}${path}`,
app: (path) => `http://localhost:${port.app}${path}`,
}
var provider = require('./util/provider')
var client = require('./util/client')
var t = require('assert')
var request = require('request-compose').extend({
Request: {cookie: require('request-cookie').Request},
Response: {cookie: require('request-cookie').Response},
}).client
var hapi = parseInt(require('hapi/package.json').version.split('.')[0])
var port = {oauth1: 5000, oauth2: 5001, app: 5002}
var url = {
oauth1: (path) => `http://localhost:${port.oauth1}${path}`,
oauth2: (path) => `http://localhost:${port.oauth2}${path}`,
app: (path) => `http://localhost:${port.app}${path}`,
}
var provider = require('./util/provider')
var client = require('./util/client')
it('extend', async () => {
var {body} = await request({url: 'http://localhost:5000/qstext'})
t.deepStrictEqual(body, {nested: {querystring: 'true'}})
var {body} = await compose.client({url: 'http://localhost:5000/qstext'})
t.equal(body, 'nested%5Bquerystring%5D=true')
})
var t = require('assert')
var urlib = require('url')
var http = require('http')
var qs = require('qs')
var request = require('request-compose').extend({
Request: {cookie: require('request-cookie').Request},
Response: {cookie: require('request-cookie').Response},
}).client
var express = require('express')
var session = require('express-session')
var Koa = require('koa')
var koasession = require('koa-session')
var mount = require('koa-mount')
var convert = require('koa-convert')
var koaqs = require('koa-qs')
var Hapi = require('hapi')
var yar = require('yar')
var t = require('assert')
var request = require('request-compose').extend({
Request: {cookie: require('request-cookie').Request},
Response: {cookie: require('request-cookie').Response},
}).client
var port = {oauth2: 5001, app: 5002}
var url = {
oauth2: (path) => `http://localhost:${port.oauth2}${path}`,
app: (path) => `http://localhost:${port.app}${path}`,
}
var provider = require('./util/provider')
var client = require('./util/client')
describe('middleware', () => {
var server = {oauth2: null}
var request = require('request-compose').client
;(async () => {
try {
var {res, body} = await request({
url: 'https://api.github.com/users/simov',
headers: {
'user-agent': 'request-compose'
}
})
console.log(res.statusCode, res.statusMessage)
console.log(res.headers['x-ratelimit-remaining'])
console.log(body)
}
catch (err) {
console.error(err)
}
var compose = require('request-compose')
var Request = compose.Request
var Response = compose.Response
;(async () => {
try {
var {res, body} = await compose(
Request.defaults({headers: {'user-agent': 'request-compose'}}),
Request.url('https://api.github.com/users/simov'),
Request.send(),
Response.buffer(),
Response.string(),
Response.parse(),
)()
console.log(res.statusCode, res.statusMessage)
console.log(res.headers['x-ratelimit-remaining'])
console.log(body)
}
var compose = require('request-compose')
var Request = compose.Request
var Response = compose.Response
;(async () => {
try {
var {res, body} = await compose(
Request.defaults({headers: {'user-agent': 'request-compose'}}),
Request.url('https://api.github.com/users/simov'),
Request.send(),
Response.buffer(),
Response.string(),
Response.parse(),
)()
console.log(res.statusCode, res.statusMessage)
console.log(res.headers['x-ratelimit-remaining'])
console.log(body)
}
catch (err) {