# railgun.Sequencer

Railgun's sequencer tool is used to set up multiple requests at once, one for each element of a list
whose elements will be used to modify the requests. These requests all running in parallel.

Example:

```js
const railgun = require('railgun')

// A list of passwords we will try to authenticate as admin with.
let passwords = [
  'Password1',
  'hunter2',
  '12345678'
]
let sequencer = new railgun.Sequencer(passwords)

// Create a request transform that tells the `request` library we are using Content-Type: application/json
// and want to set the body to our attack payload, containing whichever of the passwords the
// request in question was created for.
sequencer.transform((request, password, next) => {
  request.options.json = true
  request.options.body = {
    username: 'admin',
    password: password
  }
  next()
})

let requestBase = new railgun.requests.Builder('POST', 'vulnsite.horse')

// Run one request, based on requestBase, for each password.
sequencer.run(requestBase)
.then((responses) => {
  for (let i = 0; i < responses.length; i++) {
    if (responses[i].statusCode === 200) {
      console.log('May have authenticated as admin with password', passwords[i])
    }
  }
})
```

## Methods

### railgun.Sequencer#constructor

Create a new sequencer object, which will later create one request for each item of the array of values
provided to the sequencer.

The only argument to the constructor is an array of any kind of values. One request will be created for
each value in the array, and provided to any transform functions bound to the sequencer.

### railgun.Sequencer#transform

Sequencer#transform is very similar to middleware bound to a proxy server to manipulate requests. It
accepts a function will modify the request before it is sent.

One argument is accepted, which is a "transform function", which takes the form

```js
function (request, item, next) {
  // Use item to manipulate the request
  next()
}
```

Here, `request` is a request.Builder, `item` is one of the items from the array passed to the sequencer
constructor, and `next` is a function that must be invoked to continue running the sequencer.

Note that this method returns the sequencer object, so it is possible to directly chain multiple transform
functions one after the other. This is especially useful if you want to apply someone else's transform
before or after your own.

```js
let sequencer = new railgun.Sequencer([1,2,3,4,5])
sequencer
.transform(someOtherTransform)
.transform((request, number, next) => {
  console.log('Issuing request #', number)
  next()
})
```

### railgun.Sequencer#run

Starts the sequencer so that all of the necessary requests will be made.

Only one argument is accepted, which must be a request builder, which acts as the foundation for the
request to run through the transform functions attached to the sequencer.
