def show_link(pasted_id): """Show or visit a shortened link. This method will redirect with a 308 forwarding the original method to the redirected URL. :param paste_id: ID number (sha1) of a valid paste. :type paste_id: str :returns: str """ request = flask.request content = backend.read(pasted_id) if content: return_url = urlparse.urljoin( request.url_root, backend.local_url(pasted_id, backend='show_link') ) return_headers = { 'Referer': return_url, 'Referrer-Policy': 'unsafe-url' } return_headers.update(CACHE_HEADERS) return flask.redirect(content, code=308), return_headers else: flask.abort(404)
def show_paste_raw(pasted_id): try: content = backend.read(pasted_id) if content: return_headers = {'Content-Type': 'text/plain; charset="utf-8"'} return content, 200, return_headers else: raise exceptions.NotFound except exceptions.NotFound: flask.abort(404)
def show_link_data(pasted_id): request = flask.request content = backend.read(pasted_id) if content: response = flask.make_response( flask.render_template('return_link.html', go_to_remote_url='/l/{}'.format(pasted_id), content=content, remote_url=urlparse.urljoin( request.url_root, backend.local_url(pasted_id, backend='show_link')))) response.headers = _add_headers(response.headers) return response else: flask.abort(404)
def show_paste(pasted_id): request = flask.request content = backend.read(pasted_id) if content: response = flask.make_response( flask.render_template( 'return_paste.html', url=backend.local_url(pasted_id, backend='show_paste'), content=content, remote_url=request.url, )) response.headers = _add_headers(response.headers) return response else: flask.abort(404)
def show_paste_raw(pasted_id): """Show the raw content of a paste. All requests will be forwarded to the CDN provider and any returned object will be formatted as raw text encoded UTF-8. :param paste_id: ID number (sha1) of a valid paste :type paste_id: str :returns: str """ request = flask.request content = backend.read(pasted_id) if content: return_headers = { 'Content-Type': 'text/plain; charset="utf-8"', 'Location': urlparse.urljoin( request.url_root, backend.local_url(pasted_id, backend='show_paste') ) } return_headers.update(CACHE_HEADERS) return content, 200, return_headers else: flask.abort(404)
def show_link(pasted_id): content = backend.read(pasted_id) if content: return flask.redirect(content, code=308), CACHE_HEADERS else: flask.abort(404)