Skip to content

Commit

Permalink
Set User-Agent header for HTTP requests
Browse files Browse the repository at this point in the history
  • Loading branch information
jwodder committed Nov 9, 2023
1 parent e0ad333 commit 56f9812
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/tinuous/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import heapq
import os
from pathlib import Path, PurePosixPath
import platform
import re
from shutil import rmtree
import tempfile
Expand All @@ -20,6 +21,7 @@
from requests.exceptions import ChunkedEncodingError
from requests.exceptions import ConnectionError as ReqConError

from . import __url__, __version__
from .util import (
delay_until,
expand_template,
Expand All @@ -28,6 +30,15 @@
sanitize_pathname,
)

USER_AGENT = "tinuous/{} ({}) requests/{} {}/{}".format(
__version__,
__url__,
requests.__version__,
platform.python_implementation(),
platform.python_version(),
)


COMMON_STATUS_MAP = {
"success": "success",
"passed": "success",
Expand Down Expand Up @@ -94,6 +105,7 @@ class APIClient:
def __init__(self, base_url: str, headers: dict[str, str], is_github: bool = False):
self.base_url = base_url
self.session = requests.Session()
self.session.headers["User-Agent"] = USER_AGENT
self.session.headers.update(headers)
self.is_github = is_github

Expand Down

0 comments on commit 56f9812

Please sign in to comment.