diff --git a/templates/create.html b/templates/create.html new file mode 100644 index 0000000..d418112 --- /dev/null +++ b/templates/create.html @@ -0,0 +1,104 @@ + + + + + Short a link + + + + +
+ URL: +
+ Method: + + + + + + + + + + + + + + + + + + +
Use the 301 Moved Permanently HTTP status code to tell the client the target of the url.
+
Use the 302 Found HTTP status code to tell the client the target of the url.
+
Deliver a HTML site with a containing html-<meta>-tag to redirect to the new url.
+
This will use javascript so set the window.location to the desired url.
+ + diff --git a/urlshort.py b/urlshort.py index fbd815a..95130f0 100644 --- a/urlshort.py +++ b/urlshort.py @@ -28,8 +28,7 @@ def teardown_request(exception): @app.route("/") @limiter.exempt def root(): - - return "Welcome to root!" + return render_template("create.html") @app.route("/") @limiter.exempt @@ -38,17 +37,21 @@ def paste(pasteID): if target is None: return redirect("/", 301) else: - url = urlparse(target["target"]) - if url.scheme is "": - target = "http://" + url.path - else: - target = url.scheme + "://" + url.netloc + url.path + url = urlparse(target["target"]).geturl() + # Here is the right place to implement different redirection methods return redirect(target, 301) @app.route("/new") @limiter.exempt def new_short(): target_url = request.args.get("target", "") + target_url = urlparse(target_url) + if target_url.path is "" and target_url.netloc is "": + return "invalid request!" + if url.scheme is "": + target_url = "http://" + target_url.geturl() + else: + target_url = target_url.geturl() paste_id = add_redirect(target_url, 1) return render_template("short_completed.html", paste_id=paste_id, server_url=request.host + "/")