def shorten(url): if len(url) > app.config["MAX_URL_LENGTH"]: abort(414) if not url_valid(url) or is_fhost_url(url) or "\n" in url: abort(400) u = URL.get(url) return u.geturl()
def shorten(url): if len(url) > app.config["MAX_URL_LENGTH"]: abort(414) # resolve redirects r = requests.head(url) if 300 < r.status_code < 400: url = r.headers['location'] if not url_valid(url) or is_fhost_url(url) or "\n" in url: abort(400) u = URL.get(url) return u.geturl()
def shorten(url): if len(url) > app.config["MAX_URL_LENGTH"]: abort(414) if not url_valid(url) or is_fhost_url(url) or "\n" in url: abort(400) existing = URL.query.filter_by(url=url).first() if existing: return existing.geturl() else: u = URL(url) db.session.add(u) db.session.commit() return u.geturl()
def report(): if request.method == "POST": link = request.form.get("link") captcha_response = request.form.get("g-recaptcha-response") user_passed_captcha = check_captcha(captcha_response) if url_valid(link) and user_passed_captcha: proceed_link.queue(link) return render_template( "contact.html", result="Admin will check your problem shortly", site_key=current_app.config.get("CAPTCHA_SITE_KEY")) return render_template( "contact.html", result="Input is not a valid url or refer to another site", site_key=current_app.config.get("CAPTCHA_SITE_KEY")) return render_template("contact.html", site_key=current_app.config.get("CAPTCHA_SITE_KEY"))
def shorten(url): # handler to convert gopher links to HTTP(S) proxy gopher = "gopher://" length = len(gopher) if url[:length] == gopher: url = "https://gopher.envs.net/{}".format(url[length:]) if len(url) > app.config["MAX_URL_LENGTH"]: abort(414) if not url_valid(url) or is_fhost_url(url) or "\n" in url: abort(400) existing = URL.query.filter_by(url=url).first() if existing: return existing.geturl() else: u = URL(url) db.session.add(u) db.session.commit() return u.geturl()
def validate(url): ''' Returns True if the url is valid, otherwise returns :class: `~validators.utils.ValidationFailure'. ''' return url_valid(url)