Left: | ||
Right: |
LEFT | RIGHT |
---|---|
1 # This file is part of the Juju GUI, which lets users view and manage Juju | 1 # This file is part of the Juju GUI, which lets users view and manage Juju |
2 # environments within a graphical interface (https://launchpad.net/juju-gui). | 2 # environments within a graphical interface (https://launchpad.net/juju-gui). |
3 # Copyright (C) 2013 Canonical Ltd. | 3 # Copyright (C) 2013 Canonical Ltd. |
4 # | 4 # |
5 # This program is free software: you can redistribute it and/or modify it under | 5 # This program is free software: you can redistribute it and/or modify it under |
6 # the terms of the GNU Affero General Public License version 3, as published by | 6 # the terms of the GNU Affero General Public License version 3, as published by |
7 # the Free Software Foundation. | 7 # the Free Software Foundation. |
8 # | 8 # |
9 # This program is distributed in the hope that it will be useful, but WITHOUT | 9 # This program is distributed in the hope that it will be useful, but WITHOUT |
10 # ANY WARRANTY; without even the implied warranties of MERCHANTABILITY, | 10 # ANY WARRANTY; without even the implied warranties of MERCHANTABILITY, |
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
245 | 245 |
246 Receive a path that will be used as part of the resulting URL used to | 246 Receive a path that will be used as part of the resulting URL used to |
247 retrieve the response. | 247 retrieve the response. |
248 The response will then be sent back to the client. | 248 The response will then be sent back to the client. |
249 """ | 249 """ |
250 url = join_url(self.target_url, path, self.request.query) | 250 url = join_url(self.target_url, path, self.request.query) |
251 response = yield self.send_request(url) | 251 response = yield self.send_request(url) |
252 if response is not None: | 252 if response is not None: |
253 self.send_response(response) | 253 self.send_response(response) |
254 | 254 |
255 # Handle POST requests the same way GET ones are handled. | 255 # Handle POST requests the same way GET requests are handled. |
bac
2014/04/09 16:32:42
s/ones/requests/ -- just reads better.
frankban
2014/04/09 16:49:06
Done.
| |
256 post = get | 256 post = get |
257 | 257 |
258 @gen.coroutine | 258 @gen.coroutine |
259 def send_request(self, url): | 259 def send_request(self, url): |
260 """Send an asynchronous request to the given URL. | 260 """Send an asynchronous request to the given URL. |
261 | 261 |
262 Return the server response. | 262 Return the server response. |
263 If an error occurs in the communication, return None and call | 263 If an error occurs in the communication, return None and call |
264 self._send_error with the given error. | 264 self._send_error with the given error. |
265 """ | 265 """ |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
310 super(JujuProxyHandler, self).initialize( | 310 super(JujuProxyHandler, self).initialize( |
311 target_url, validate_cert=False) | 311 target_url, validate_cert=False) |
312 self.default_charm_icon_url = urlparse.urljoin( | 312 self.default_charm_icon_url = urlparse.urljoin( |
313 charmworld_url, DEFAULT_CHARM_ICON_PATH) | 313 charmworld_url, DEFAULT_CHARM_ICON_PATH) |
314 | 314 |
315 @gen.coroutine | 315 @gen.coroutine |
316 def get(self, path): | 316 def get(self, path): |
317 """Handle GET requests. | 317 """Handle GET requests. |
318 See the ProxyHandler.get method. | 318 See the ProxyHandler.get method. |
319 | 319 |
320 Override to handle the case a when a charm icon is not found. | 320 Override to handle the case when a charm icon is not found. |
bac
2014/04/09 16:32:42
s/a when/when/ or /for when/?
frankban
2014/04/09 16:49:06
Done.
| |
321 """ | 321 """ |
322 url = join_url(self.target_url, path, self.request.query) | 322 url = join_url(self.target_url, path, self.request.query) |
323 response = yield self.send_request(url) | 323 response = yield self.send_request(url) |
324 if response is not None: | 324 if response is not None: |
325 if response.code == 404 and self._charm_icon_requested(path): | 325 if response.code == 404 and self._charm_icon_requested(path): |
326 # This is a request for a charm icon file, and the icon is not | 326 # This is a request for a charm icon file, and the icon is not |
327 # found: redirect to the fallback icon hosted on charmworld. | 327 # found: redirect to the fallback icon hosted on charmworld. |
328 self.redirect(self.default_charm_icon_url) | 328 self.redirect(self.default_charm_icon_url) |
329 else: | 329 else: |
330 # Return the response to the client as usual. | 330 # Return the response to the client as usual. |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
374 | 374 |
375 | 375 |
376 class HttpsRedirectHandler(web.RequestHandler): | 376 class HttpsRedirectHandler(web.RequestHandler): |
377 """Permanently redirect all the requests to the equivalent HTTPS URL.""" | 377 """Permanently redirect all the requests to the equivalent HTTPS URL.""" |
378 | 378 |
379 def get(self): | 379 def get(self): |
380 """Handle GET requests.""" | 380 """Handle GET requests.""" |
381 request = self.request | 381 request = self.request |
382 url = 'https://{}{}'.format(request.host, request.uri) | 382 url = 'https://{}{}'.format(request.host, request.uri) |
383 self.redirect(url, permanent=True) | 383 self.redirect(url, permanent=True) |
LEFT | RIGHT |