New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

mof-uarotate

Package Overview
Dependencies
Maintainers
2
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mof-uarotate - npm Package Compare versions

Comparing version 1.0.0 to 1.0.1

ua

32

index.js
'use strict'
module.exports = function(userAgents) {
const fs = require('fs')
const path = require('path')
let UA = {
values:userAgents,
curIndex:0,
next:function() {
this.curIndex = this.curIndex % this.values.length
return this.values[this.curIndex++]
}
module.exports = function() {
const useragent = fs.readFileSync(path.resolve(__dirname,'ua') ).toString().split('\n');
let UA = {
values:useragent,
curIndex:0,
next:function() {
this.curIndex = this.curIndex % this.values.length;
return this.values[this.curIndex++];
}
}
return function(ctx, next) {
if(ctx.opt.rotateUA) {
ctx.opt['User-Agent'] = UA.next()
}
return next()
}
}
return function(ctx, next) {
ctx.opt.headers = ctx.opt.headers || {};
ctx.opt.headers['User-Agent'] = UA.next();
return next();
}
}
{
"name": "mof-uarotate",
"version": "1.0.0",
"version": "1.0.1",
"description": "middleware of floodesh, which rotates User-Agent automatically",

@@ -5,0 +5,0 @@ "main": "index.js",

'use strict'
const should = require('should'),
Mof = require('mof'),
uarotate = require('..')
Mof = require('mof'),
uarotate = require('..')

@@ -10,41 +10,38 @@ let mof, ctx

describe('mof-uarotate()', function(){
before(function(){
mof = new Mof()
mof.use(uarotate())
ctx = {
opt:{
}
}
})
before(function(){
mof = new Mof()
mof.use(uarotate(['ua1','ua2','ua3']))
console.log(' Init with [\'ua1\',\'ua2\',\'ua3\']')
ctx = {
opt:{
rotateUA:true
}
}
})
it('should be Mozilla/5.0 (compatible; U; ABrowse 0.6; Syllable) AppleWebKit/420+ (KHTML, like Gecko)', function(done){
mof.callback( ctx => {
ctx.opt.headers['User-Agent'].should.be.eql('Mozilla/5.0 (compatible; U; ABrowse 0.6; Syllable) AppleWebKit/420+ (KHTML, like Gecko)')
done()
})(ctx)
})
it('should be ua1', function(done){
mof.callback( ctx => {
ctx.opt['User-Agent'].should.be.eql('ua1')
done()
})(ctx)
})
it('should be Mozilla/5.0 (compatible; U; ABrowse 0.6; Syllable) AppleWebKit/420+ (KHTML, like Gecko)', function(done){
mof.callback( ctx => {
ctx.opt.headers['User-Agent'].should.be.eql('Mozilla/5.0 (compatible; U; ABrowse 0.6; Syllable) AppleWebKit/420+ (KHTML, like Gecko)')
done()
})(ctx)
})
it('should be ua2', function(done){
mof.callback( ctx => {
ctx.opt['User-Agent'].should.be.eql('ua2')
done()
})(ctx)
})
it('should be Mozilla/5.0 (compatible; ABrowse 0.4; Syllable)', function(done){
mof.callback( ctx => {
ctx.opt.headers['User-Agent'].should.be.eql('Mozilla/5.0 (compatible; ABrowse 0.4; Syllable)')
done()
})(ctx)
})
it('should be ua3', function(done){
mof.callback( ctx => {
ctx.opt['User-Agent'].should.be.eql('ua3')
done()
})(ctx)
})
it('should be ua1', function(done){
mof.callback( ctx => {
ctx.opt['User-Agent'].should.be.eql('ua1')
done()
})(ctx)
})
})
it.skip('should be ua1', function(done){
mof.callback( ctx => {
ctx.opt.headers['User-Agent'].should.be.eql('ua1')
done()
})(ctx)
})
})
SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc