Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MRG]: badge_base_url can be a function that gets the parameter from the HTTP RequestHandler #1031

Merged
merged 3 commits into from
Dec 17, 2019

Conversation

manics
Copy link
Member

@manics manics commented Dec 14, 2019

This allows the badge_base_url setting and therefore the BINDER_LAUNCH_HOST environment variable to be set from a HTTP request, and is intended to allow a BinderHub to have different values of the variable depending on the original source of the request.

For example, Gesis currently has a mix of https://mybinder.org and https://notebooks.gesis.org/binder in different places. By changing badge_base_url to check for a parameter in the request it should be possible to have the URLs match consistently depending on whether the user was redirected from mybinder (e.g. the redirector could set a query parameter binder_launch_host=https://mybinder.org/) or directly (no parameter, default behaviour).

For example:

    def badge_base_url(handler):
        launch_host = (
            handler.request.headers.get('X-Binder-Launch-Host', '') or
            handler.get_argument('binder_launch_host', ''))
        print('launch_host', launch_host)
        if launch_host and not launch_host.endswith('/'):
            launch_host += '/'
        if launch_host == 'https://mybinder.org/':
            return launch_host
        return ''
    c.BinderHub.badge_base_url = badge_base_url

See discussion starting from jupyterhub/mybinder.org-deploy#1284 (comment)

I've tested this locally using curl:
curl http://binder-test-host/build/gh/manics/jupyter-offlinenotebook/7ba3520553c414d0b55e80b96c0f6df85f903078?binder_launch_host=https://mybinder.org
this will spit out a URL and token that can be copied into a browser.

To work with the mybinder federation this will require the parameter to be passed in proxy requests made by the redirector:

@manics manics changed the title Optionally use X-Binder-Launch-Host header WIP: Optionally use X-Binder-Launch-Host header Dec 14, 2019
@manics manics changed the title WIP: Optionally use X-Binder-Launch-Host header WIP: badge_base_url can be a function that gets the parameter from the HTTP request Dec 14, 2019
Instead of using a new setting launch_host_allowed reuse the badge_base_url setting by allowing it to be a callable that is passed the current RequestHandler. It can then be configured to extract the badge_base_url in any way, for example by looking for a X-Binder-Launch-Host header or a query parameter.
@manics manics changed the title WIP: badge_base_url can be a function that gets the parameter from the HTTP request WIP: badge_base_url can be a function that gets the parameter from the HTTP RequestHandler Dec 14, 2019
@manics manics changed the title WIP: badge_base_url can be a function that gets the parameter from the HTTP RequestHandler [MRG]: badge_base_url can be a function that gets the parameter from the HTTP RequestHandler Dec 14, 2019
binderhub/builder.py Outdated Show resolved Hide resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants