Skip to content

Commit

Permalink
Set "User-Agent" header for http fetch handler (requests) to "bdbag/{…
Browse files Browse the repository at this point in the history
…version} (requests/{version}".

Update Pipfile.lock.
Bump version.
  • Loading branch information
mikedarcy committed May 5, 2021
1 parent a2f2f1b commit 9b2b728
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 45 deletions.
82 changes: 41 additions & 41 deletions Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion bdbag/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
from distutils.util import strtobool
from pkg_resources import parse_version, get_distribution, DistributionNotFound

__version__ = "1.6.1"
__version__ = "1.6.2"
__bagit_version__ = "1.8.1"
__bagit_profile_version__ = "1.3.1"

Expand Down
8 changes: 5 additions & 3 deletions bdbag/fetch/transports/fetch_http.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@
import logging
import certifi
import requests
from requests.utils import default_user_agent
from requests.adapters import HTTPAdapter
from requests.packages.urllib3.util.retry import Retry
from bdbag import urlsplit, stob, get_typed_exception
from bdbag import urlsplit, stob, get_typed_exception, VERSION
from bdbag.bdbag_config import DEFAULT_CONFIG, DEFAULT_FETCH_CONFIG, FETCH_CONFIG_TAG, \
FETCH_HTTP_REDIRECT_STATUS_CODES_TAG, DEFAULT_FETCH_HTTP_SESSION_CONFIG, DEFAULT_FETCH_HTTP_REDIRECT_STATUS_CODES
from bdbag.fetch import *
Expand All @@ -31,7 +32,7 @@
logger = logging.getLogger(__name__)

CHUNK_SIZE = 10 * Megabyte
HEADERS = {"Connection": "keep-alive"}
HEADERS = {"User-Agent": "bdbag/%s (%s)" % (VERSION, default_user_agent())}


class HTTPFetchTransport(BaseFetchTransport):
Expand Down Expand Up @@ -178,7 +179,8 @@ def get_session(self, url):

def fetch(self, url, output_path, **kwargs):
try:
headers = kwargs.get("headers", HEADERS)
headers = kwargs.get("headers", {"Connection": "keep-alive"})
headers.update(HEADERS)
redirect_status_codes = self.config.get(
FETCH_HTTP_REDIRECT_STATUS_CODES_TAG, DEFAULT_FETCH_HTTP_REDIRECT_STATUS_CODES)

Expand Down
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
long_description=readme,
long_description_content_type='text/markdown',
url='https://github.com/fair-research/bdbag/',
author="Mike D'Arcy",
maintainer='USC Information Sciences Institute, Informatics Systems Research Division',
maintainer_email='[email protected]',
version=__version__,
Expand Down

0 comments on commit 9b2b728

Please sign in to comment.