Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add configuration option for additional request headers #96

Merged
merged 3 commits into from
Apr 1, 2024

Conversation

dardanbujupaj
Copy link
Contributor

@dardanbujupaj dardanbujupaj commented Mar 18, 2024

Pull Request

Related issue

none

What does this PR do?

We're using scrapix to index our documentation.
Some parts of the documentation are protected, so we need a way to send some authentication information with the crawler requests.
This PR adds a new configuration property additional_request_headers which are applied to each request in a pre navigation hook.
This way we're able to either send an Authorization header (basic, bearer etc.) or a custom auth header (e.g. x-access-key), so it should be quite flexible for any usecase.

  • add configuration option for additional_request_headers
  • add a pre navigation hook to add those headers to the request

add a pre navigation hook to add thos headers to the request
@dardanbujupaj
Copy link
Contributor Author

PS: we're running this from our fork, but I thought the changes might as well be relevant to this repo. feel free to merge or close the PR as you see fit 🙃

@brunoocasali
Copy link
Member

Hey @dardanbujupaj, thanks a lot for your contribution!!

Can you include some examples of how you can use this feature in the README?

async (request) => {
return await request.continue({
headers: {
...request.headers(),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought this would be an object instead of a function 🤔

https://docs.apify.com/sdk/js/docs/2.3/api/request#headers

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this case we're in a PuppeteerCrawlingContext, which means we have a Puppeteer HTTPRequest with a headers() method, see https://pptr.dev/api/puppeteer.httprequest.headers

@dardanbujupaj
Copy link
Contributor Author

Can you include some examples of how you can use this feature in the README?

@brunoocasali Sure, I'll add something this evening.

@dardanbujupaj
Copy link
Contributor Author

@brunoocasali added the configuration property description to the readme with a short example.

Let me know if there's anything else to improve!

Copy link
Member

@brunoocasali brunoocasali left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot for your contribution!

bors merge

@brunoocasali brunoocasali added the enhancement New feature or request label Apr 1, 2024
Copy link

meili-bors bot commented Apr 1, 2024

Configuration problem:
bors.toml: not found

@brunoocasali brunoocasali merged commit a1d1988 into meilisearch:main Apr 1, 2024
10 of 11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants