Skip to content

Enable HTTP header customization for URLOperations #336

Closed
@mih

Description

@mih

this would be the patch:

diff --git a/datalad_next/url_operations/http.py b/datalad_next/url_operations/http.py
index 8700b7b..2d30c64 100644
--- a/datalad_next/url_operations/http.py
+++ b/datalad_next/url_operations/http.py
@@ -36,13 +36,24 @@ class HttpUrlOperations(UrlOperations):
     authentication challenges.
     """
 
-    _headers = {
-        'user-agent': user_agent('datalad', datalad.__version__),
-    }
+    def __init__(self, cfg=None, headers=None):
+        """
+        Parameters
+        ----------
+        cfg: ConfigManager, optional
+          A config manager instance that is consulted for any configuration
+          filesystem configuration individual handlers may support.
+        """
+        super().__init__(cfg=cfg)
+        self._headers = {
+            'user-agent': user_agent('datalad', datalad.__version__),
+        }
+        if headers:
+            self._headers.update(headers)
 
     def get_headers(self, headers: Dict | None = None) -> Dict:
         # start with the default
-        hdrs = dict(HttpUrlOperations._headers)
+        hdrs = dict(self._headers)
         if headers is not None:
             hdrs.update(headers)
         return hdrs

With the headers exposed in the constructor, we can use handler customization (that still needs to be documented #335) and supply custom headers like so:

datalad \
  -c datalad.url-handler.https://fz-juelich.sciebo.de/public.php/webdav.class=datalad_next.url_operations.http.HttpUrlOperations \
   -c 'datalad.url-handler.https://fz-juelich.sciebo.de/public.php/webdav.kwargs={"headers": {"X-Requested-With": "XMLHttpRequest"}}' \
   download \
   'https://fz-juelich.sciebo.de/public.php/webdav/king/hubert-neufeld-j-udI4zim2E-unsplash.jpg'

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions