-
Notifications
You must be signed in to change notification settings - Fork 0
/
url.clj
33 lines (29 loc) · 1.01 KB
/
url.clj
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
(ns link-checker.url
(:require [cemerick.url :as url-utils]
[clojure.string :as string])
(:import (java.net URL)))
(defn base-path [u]
(let [u (URL. u)]
(str (.getProtocol u)
"://"
(.getHost u)
(when (pos? (.getPort u))
(str ":" (.getPort u))))))
(defn prepare-url [u]
(let [url (URL. u)
path (.getPath url)
query (.getQuery url)
ref (.getRef url)
base (base-path u)
encoded-path (string/join "/"
(map #(url-utils/url-encode
;(try (url-utils/url-decode %)
; (catch Exception e
; %)
; )
%)
(string/split path #"/" -1)))]
(str base
encoded-path
(when query (str "?" query))
(when ref (str "#" ref)))))