Skip to content

Commit 1791ed3

Browse files
committed
make HTTP user agent configurable
1 parent 43f2df8 commit 1791ed3

5 files changed

Lines changed: 9 additions & 2 deletions

File tree

config.toml.sample

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ name = "lilac"
2121
email = "lilac@example.com"
2222
# for internal error reports
2323
master = "Your Name <youremail@example.com>"
24+
# the user_agent to use for fetching HTTP resources
25+
# user_agent = "lilac/0.3 (URL; email)"
2426
# Set and unsubscribe_address to receive unsubscribe requests
2527
# unsubscribe_address = "unsubscribe@example.com"
2628
# Set to yes to automatically rebuild packages which failed to build last time

lilac2/api.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,11 @@
3737
logger = logging.getLogger(__name__)
3838

3939
_g = SimpleNamespace()
40-
UserAgent = 'lilac/0.2b (package auto-build bot, by lilydjwg)'
4140

4241
logging.getLogger('httpcore').setLevel(logging.ERROR)
4342
logging.getLogger('hpack').setLevel(logging.ERROR)
4443

4544
s = httpx.Client(http2=True)
46-
s.headers['User-Agent'] = UserAgent
4745

4846
VCS_SUFFIXES = ('-git', '-hg', '-svn', '-bzr')
4947
AUR_BLACKLIST = {

lilac2/building.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,9 @@ def call_worker(
214214
'deadline': deadline,
215215
'reponame': repo.name,
216216
}
217+
if ua := repo.user_agent:
218+
input['user_agent'] = ua
219+
217220
fd, resultpath = tempfile.mkstemp(prefix=f'{pkgbase}-', suffix='.lilac')
218221
os.close(fd)
219222
input['result'] = resultpath

lilac2/repo.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ def __init__(self, config: dict[str, Any]) -> None:
4242
self.name = config['repository']['name']
4343
self.trim_ansi_codes = not config['smtp'].get('use_ansi', False)
4444
self.commit_msg_prefix = config['lilac'].get('commit_msg_prefix', '')
45+
self.user_agent = config['lilac'].get('user_agent')
4546

4647
self.repodir = Path(config['repository']['repodir']).expanduser()
4748
self.bindmounts = config.get('bindmounts', [])

lilac2/worker.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,9 @@ def main() -> None:
224224
reports: list[Report] = []
225225
_G.add_report = partial(add_report, reports)
226226

227+
if ua := input.get('user_agent'):
228+
api.s.headers['User-Agent'] = ua
229+
227230
r: dict[str, Any]
228231
try:
229232
with load_lilac(Path('.')) as mod:

0 commit comments

Comments
 (0)