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

http_header_envs option to include http headers as an env var #835

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions voila/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,3 +85,12 @@ class VoilaConfiguration(traitlets.config.Configurable):
show_tracebacks = Bool(False, config=True, help=(
'Whether to send tracebacks to clients on exceptions.'
))

http_header_envs = List(
Unicode(),
[],
help=r"""
List of HTTP Headers that should be passed as env vars to the kernel.
Example: --VoilaConfiguration.http_header_envs="['X-CDSDASHBOARDS-JH-USER']"
""",
).tag(config=True)
9 changes: 9 additions & 0 deletions voila/handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import os
import sys
import traceback
import json

import tornado.web

Expand Down Expand Up @@ -81,6 +82,14 @@ async def get(self, path=None):
self.kernel_env['SERVER_PORT'] = str(port) if port else ''
self.kernel_env['SERVER_NAME'] = host

# Add HTTP Headers as env vars
if len(self.voila_configuration.http_header_envs) > 0:
http_headers_dict = {}
for header_name in self.voila_configuration.http_header_envs:
if header_name in self.request.headers:
http_headers_dict[header_name] = self.request.headers.get(header_name)
self.kernel_env['HTTP_HEADERS'] = json.dumps(http_headers_dict)

# we can override the template via notebook metadata or a query parameter
template_override = None
if 'voila' in notebook.metadata and self.voila_configuration.allow_template_override in ['YES', 'NOTEBOOK']:
Expand Down