Skip to content

Commit 7778dc3

Browse files
committed
Allow for redundant accesses of same endpoint
1 parent ac50d2e commit 7778dc3

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

notebook/terminal/handlers.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
# Copyright (c) Jupyter Development Team.
44
# Distributed under the terms of the Modified BSD License.
55

6+
import json
67
from tornado import web
78
import terminado
89
from notebook._tz import utcnow
@@ -19,11 +20,17 @@ def get(self, term_name):
1920

2021

2122
class NewTerminalHandler(IPythonHandler):
22-
"""Render the terminal interface."""
23+
"""Renders a new terminal interface using the named argument."""
2324
@web.authenticated
2425
def get(self, term_name):
25-
self.terminal_manager.create_with_name(term_name)
2626
new_path = self.request.path.replace("new/{}".format(term_name), term_name)
27+
if term_name in self.terminal_manager.terminals:
28+
self.set_header('Location', new_path)
29+
self.set_status(302)
30+
self.finish(json.dumps(self.terminal_manager.get_terminal_model(term_name)))
31+
return
32+
33+
self.terminal_manager.create_with_name(term_name)
2734
self.redirect(new_path)
2835

2936

notebook/terminal/tests/test_terminals_api.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,16 @@ def test_create_terminal_via_get(self):
7676
self.assertIsInstance(foo_term, dict)
7777
self.assertEqual(foo_term['name'], 'foo')
7878

79-
with assert_http_error(409):
80-
self.term_api._req('GET', 'terminals/new/foo')
79+
# hit the same endpoint a second time and ensure 302 with Location is returned
80+
r = self.term_api._req('GET', 'terminals/new/foo')
81+
# Access the "interesting" response from the history
82+
self.assertEqual(len(r.history), 1)
83+
r = r.history[0]
84+
foo_term = r.json()
85+
self.assertEqual(r.status_code, 302)
86+
self.assertEqual(r.headers['Location'], self.url_prefix + "terminals/foo")
87+
self.assertIsInstance(foo_term, dict)
88+
self.assertEqual(foo_term['name'], 'foo')
8189

8290
r = self.term_api.shutdown('foo')
8391
self.assertEqual(r.status_code, 204)

0 commit comments

Comments
 (0)