def get(self, request, name): """ Get token data by name """ token = settings.TOKEN_MANAGER.fetch(name) if not token: return error_404(request.path) return Response(token)
def get(self, request, request_path): # Remove multiple slashes from path, to make sure things match request_path = re.sub("//+", "/", request_path) redirect_record = settings.REDIRECT_MANAGER.fetch(request_path) if not redirect_record: return error_404(request.path) response = HttpResponsePermanentRedirect(redirect_record['target_url']) return set_headers_for_type(response, get_mimetype(request_path))
def get(self, request, redirect_path): """ Get redirect data by name """ redirect_record = settings.REDIRECT_MANAGER.fetch( unquote(redirect_path)) if not redirect_record: return error_404(request.path) return Response(redirect_record)
def delete(self, request, name): """ Delete a single named authentication token, 204 if successful """ body = settings.TOKEN_MANAGER.delete(name) or {} if body: body['message'] = "Successfully deleted." else: return error_404(request.path) return Response(body, 204)
def delete(self, request, redirect_path): """ Delete a single redirect by its request URL path, 204 if successful """ body = settings.REDIRECT_MANAGER.delete(unquote(redirect_path)) or {} if body: body['message'] = "Successfully deleted." else: return error_404(request.path) return Response(body, 204)
def get(self, request, request_path): # Remove multiple slashes from path, to make sure things match request_path = re.sub("//+", "/", request_path) redirect_record = settings.REDIRECT_MANAGER.fetch(request_path) if not redirect_record: return error_404(request.path) permanent = redirect_record.get('permanent', False) response = redirect(redirect_record['target_url'], permanent=permanent) # Cache permanent redirect longtime. Temporary, not so much. if permanent: response['Cache-Control'] = 'max-age=31556926' else: response['Cache-Control'] = 'max-age=60' return set_headers_for_type(response, get_mimetype(request_path))
def put(self, request, redirect_path): """ Update target URL for a redirect """ target_url = request.DATA.get('target_url') permanent = request.DATA.get('permanent') if permanent is not None: permanent = permanent.lower() in ('true', 'yes', 'on') if not settings.REDIRECT_MANAGER.exists(redirect_path): return error_404(request.path) redirect_record = settings.REDIRECT_MANAGER.update( unquote(redirect_path), target_url, permanent ) return Response(redirect_record)