Skip to content

Commit

Permalink
Merge pull request #2 from vamsiikrishna/add_req_headers_body
Browse files Browse the repository at this point in the history
Add req headers body
  • Loading branch information
vamsiikrishna committed Aug 21, 2017
2 parents a89a159 + 6a827cf commit 2880b94
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 11 deletions.
30 changes: 24 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,33 @@ Download the latest release from GitHub [Releases](https://github.com/vamsiikris
## Usage

Usage:
`` ./vex.phar vex <url> [<n>] [<c>] [<m>] ``
`` vex [options] [--] <url> [<n>] [<c>]
``

Arguments:
```
url The URL to which the requests should be sent
n Number of requests to be made [default: 1]
c Concurrency [default: 1]
m HTTP Method [default: "GET"]
url The URL to which the requests should be sent
n Number of requests to be made [default: 1]
c Concurrency [default: 1]
```
Options:
```
-m, --method[=METHOD] HTTP Method [default: "GET"]
-H, --headers[=HEADERS] Headers (multiple values allowed)
-d, --body[=BODY] Request body
```
Example :

./vex.phar vex http://127.0.0.1:8000 1000 10
- 1000 Get requests with 10 concurrency to `http://127.0.0.1:8000`

`./vex.phar vex http://127.0.0.1:8000 1000 10`

- 1000 POST requests with 10 concurrency to `http://127.0.0.1:8000` with custom headers and body

```
./vex.phar vex http://127.0.0.1:8000 1000 10 \
-m "POST" \
-H "accept:application/json, text/plain, */*" \
-H "accept-language:en-IN,en-GB;q=0.8,en-US;q=0.6,en;q=0.4" \
-d "{\"message\": \"Hello world! Your JustAPIs instance is running correctly.\"}"
```
14 changes: 9 additions & 5 deletions src/Vamsi/Vex/Command/VexCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Symfony\Component\Console\Helper\ProgressBar;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use GuzzleHttp\TransferStats;
use Symfony\Component\Console\Input\InputArgument;
Expand All @@ -23,8 +24,9 @@ protected function configure()
->addArgument('url', InputArgument::REQUIRED, 'The URL to which the requests should be sent')
->addArgument('n', InputArgument::OPTIONAL, 'Number of requests to be made', 1)
->addArgument('c', InputArgument::OPTIONAL, 'Concurrency', 1)
->addArgument('m', InputArgument::OPTIONAL, 'HTTP Method', 'GET');

->addOption('method', 'm', InputOption::VALUE_OPTIONAL, 'HTTP Method', 'GET')
->addOption('headers', 'H', InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY, 'Headers', null)
->addOption('body', 'd', InputOption::VALUE_OPTIONAL, 'Request body', null);
}

protected function execute(InputInterface $input, OutputInterface $output)
Expand All @@ -34,7 +36,9 @@ protected function execute(InputInterface $input, OutputInterface $output)
$url = $input->getArgument('url');
$number_of_requests = $input->getArgument('n');
$concurrency = $input->getArgument('c');
$http_method = $input->getArgument('m');
$http_method = $input->getOption('method');
$headers = $input->getOption('headers');
$body = $input->getOption('body');

$output->writeln("Sending $number_of_requests requests with $concurrency Concurrency");
$client = new Client([
Expand All @@ -50,10 +54,10 @@ protected function execute(InputInterface $input, OutputInterface $output)

$progress->setFormat(' %current%/%max% [%bar%] %percent:3s%% %elapsed:6s%/%estimated:-6s% %memory:6s%');
$progress->start();
$requests = function ($total) use ($url, $http_method) {
$requests = function ($total) use ($url, $http_method, $headers, $body) {
$uri = $url;
for ($i = 0; $i < $total; $i++) {
yield new Request($http_method, $uri);
yield new Request($http_method, $uri, $headers, $body);
}
};

Expand Down

0 comments on commit 2880b94

Please sign in to comment.