Skip to content

Commit

Permalink
Add auth option (#81)
Browse files Browse the repository at this point in the history
  • Loading branch information
nlemoine authored Nov 27, 2021
1 parent 6ef7f5b commit e6ce7cb
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,12 @@ By default, the crawler will respect robots data. You can ignore them though wit
http-status-check scan https://example.com --ignore-robots
```

If your site requires a basic authentification, you can use the `--auth` option:

```bash
http-status-check scan https://example.com --auth=username:password
```

## Testing

To run the tests, first make sure you have [Node.js](https://nodejs.org/) installed. Then start the included node based server in a separate terminal window:
Expand Down
10 changes: 10 additions & 0 deletions src/ScanCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,12 @@ protected function configure(): void
InputOption::VALUE_NONE,
'Skips checking the SSL certificate'
)
->addOption(
'auth',
'a',
InputOption::VALUE_OPTIONAL,
'Username and password for basic auth (username:password)'
)
->addOption(
'options',
'opt',
Expand Down Expand Up @@ -126,6 +132,10 @@ protected function execute(InputInterface $input, OutputInterface $output)

$clientOptions = array_merge($clientOptions, $input->getOption('options'));

if ($input->getOption('auth') && false !== strpos($input->getOption('auth'), ':')) {
$clientOptions[RequestOptions::AUTH] = explode(':', $input->getOption('auth'));
}

if ($input->getOption('user-agent')) {
$clientOptions[RequestOptions::HEADERS]['user-agent'] = $input->getOption('user-agent');
}
Expand Down

0 comments on commit e6ce7cb

Please sign in to comment.