gjtorikian / html-proofer

Test your rendered HTML files to make sure they're accurate.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

CLI support for `before_request`

asbjornu opened this issue · comments

While #758 lays some great groundwork for a fresh new CLI, there is afaict. still no support for highly dynamic features such as HTMLProofer::Runner#before_request. I need before_request to add authorization headers for specific external URLs.

The reason I would like support for before_request in the CLI is because I would like to stop using HTMLProofer as a Ruby Gem and instead move to the HTMLProofer GitHub Action. Until the GitHub Action supports before_request, I can't move away from the Ruby Gem.

Perhaps a binding-scoped eval would provide enough security and flexibility? Bound to the request object, something like this should be possible to implement without sacrificing security too much, imho:

htmlproofer --before_request="options[:headers]['Authorization'] = 'Bearer ' + env['GITHUB_TOKEN'] if URI(base_url).host.match('github\.(com|io)$')"

I think env would have to be exposed, so it's probably better to create a new object that exposes the Request object alongside ENV and a few other useful things. In GitHub Actions, I suppose it's possible to interpolate GITHUB_TOKEN like so:

    - uses: chabad360/htmlproofer@master
        with:
          arguments: --before_request="options[:headers]['Authorization'] = 'Bearer ${{ secrets.GITHUB_TOKEN }}' if URI(base_url).host.match('github\.(com|io)$')"

Thoughts?