Skip to content

Commit b0e5837

Browse files
authored
Merge pull request #76 from productboardlabs/feat/add-custom-headers
feat: custom headers
2 parents eb6e5d7 + 621a0b7 commit b0e5837

File tree

4 files changed

+55
-0
lines changed

4 files changed

+55
-0
lines changed

CONTRIBUTING.md

+13
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,19 @@ In case of Google Cloud Identity-Aware Proxy, please specify these env variables
3535
- `IAP_AUTH_CLIENT_ID` - # pick [client ID of the application](https://console.cloud.google.com/apis/credentials) you are connecting to
3636
- `IAP_AUTH_SERVICE_ACCOUNT_JSON` - # generate in [Actions](https://console.cloud.google.com/iam-admin/serviceaccounts) -> Create key -> JSON
3737

38+
#### Custom headers
39+
40+
Using `headers` configuration:
41+
42+
```json
43+
{
44+
"index_name": "my_index",
45+
"headers": {
46+
"Authorization": "Bearer <my_token>"
47+
}
48+
},
49+
```
50+
3851
### Installing Chrome Headless
3952

4053
Websites that need JavaScript for rendering are passed through ChromeDriver.

scraper/src/config/config_loader.py

+1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ class ConfigLoader:
3333
index_name_tmp = None
3434
js_wait = 0
3535
js_render = False
36+
headers = None
3637
keep_tags = []
3738
min_indexed_level = 0
3839
remove_get_params = False

scraper/src/index.py

+3
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,9 @@ def run_config(config):
5353
"Accept-Language": "en",
5454
} # Defaults for scrapy https://docs.scrapy.org/en/latest/topics/settings.html#default-request-headers
5555

56+
if config.headers is not None:
57+
headers.update(config.headers)
58+
5659
# Cloudflare Zero Trust (CF)
5760
if (os.getenv("CF_ACCESS_CLIENT_ID") and
5861
os.getenv("CF_ACCESS_CLIENT_SECRET")):
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# coding: utf-8
2+
from ...config.config_loader import ConfigLoader
3+
from .abstract import config
4+
import pytest
5+
6+
7+
class TestInit:
8+
def test_header(self):
9+
""" Should have a header """
10+
# Given
11+
c = config({
12+
'headers': {
13+
'Authorization': 'Bearer xyz'
14+
}
15+
})
16+
17+
config_loaded = ConfigLoader(c)
18+
19+
assert config_loaded.headers == {
20+
'Authorization': 'Bearer xyz'
21+
}
22+
23+
def test_multiple_header(self):
24+
""" Should have headers """
25+
# Given
26+
c = config({
27+
'headers': {
28+
'Authorization': 'Bearer xyz',
29+
'Custom': 1,
30+
}
31+
})
32+
33+
config_loaded = ConfigLoader(c)
34+
35+
assert config_loaded.headers == {
36+
'Authorization': 'Bearer xyz',
37+
'Custom': 1,
38+
}

0 commit comments

Comments
 (0)