mirror of
https://github.com/Open-Argon/http.ar.git
synced 2026-10-28 09:43:55 +00:00
add url.ar
This commit is contained in:
1 parent
4a7b6f262c
commit
5441c8f6d6
5 files changed
+4
-103
No files matched your search
+1
-1
@@ -1 +1 @@
|
|||||||
[{"Name":"neon.ar","Version":"beta1.0.2","URL":"http://isotope.wbell.dev/isotope-download?name=neon.ar\u0026version=beta1.0.2"}]
|
[{"Name":"neon.ar","Version":"beta1.0.2","URL":"http://isotope.wbell.dev/isotope-download?version=beta1.0.2\u0026name=neon.ar"},{"Name":"url.ar","Version":"1.0.0","URL":"http://isotope.wbell.dev/isotope-download?name=url.ar\u0026version=1.0.0"}]
|
||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
import "url" as url
|
import "url.ar" as url
|
||||||
|
|
||||||
let __makeFile(name, type, data) = do
|
let __makeFile(name, type, data) = do
|
||||||
let File = {name: name, type: type, data: data}
|
let File = {name: name, type: type, data: data}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import "buildResponse" as buildResponse
|
import "buildResponse" as buildResponse
|
||||||
import "parseRequest" as parseRequest
|
import "parseRequest" as parseRequest
|
||||||
import "pathCompare" as pathCompare
|
import "pathCompare" as pathCompare
|
||||||
import "url" as url
|
import "url.ar" as url
|
||||||
import "version" as version
|
import "version" as version
|
||||||
import "renderTemplate" as renderTemplate
|
import "renderTemplate" as renderTemplate
|
||||||
import "contentType" as contentType
|
import "contentType" as contentType
|
||||||
|
|||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
import "url" as url
|
import "url.ar" as url
|
||||||
|
|
||||||
let compare(structure, path) = do
|
let compare(structure, path) = do
|
||||||
let structureSplit = structure.split("/")
|
let structureSplit = structure.split("/")
|
||||||
|
|||||||
-99
@@ -1,99 +0,0 @@
|
|||||||
let decode(data) = do
|
|
||||||
data = data.replace("+", " ")
|
|
||||||
let decoded = []
|
|
||||||
let i = 0
|
|
||||||
while (i < data.length) do
|
|
||||||
if (data[i] == "%") do
|
|
||||||
decoded.append(chr(number("0x"+data[i+1:i+3])))
|
|
||||||
i = i + 3
|
|
||||||
else do
|
|
||||||
decoded.append(data[i])
|
|
||||||
i = i + 1
|
|
||||||
return decoded.join("")
|
|
||||||
|
|
||||||
let toNotEncode = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_.~"
|
|
||||||
|
|
||||||
let encode(data) = do
|
|
||||||
let encoded = []
|
|
||||||
let i = 0
|
|
||||||
while (i < data.length) do
|
|
||||||
if (data[i] in toNotEncode) do
|
|
||||||
encoded.append(data[i])
|
|
||||||
else do
|
|
||||||
encoded.append("%"+hex(ord(data[i])))
|
|
||||||
i = i + 1
|
|
||||||
return encoded.join("")
|
|
||||||
|
|
||||||
let decodeURLQuery(querytext) = do
|
|
||||||
let query = {}
|
|
||||||
let querySplit = querytext.split("&")
|
|
||||||
for (i from 0 to querySplit.length) do
|
|
||||||
let queryItem = querySplit[i].splitN("=", 2)
|
|
||||||
let nameDecoded = decode(queryItem[0])
|
|
||||||
if (queryItem.length != 2) query[nameDecoded] = ""
|
|
||||||
else query[nameDecoded] = decode(queryItem[1])
|
|
||||||
return query
|
|
||||||
|
|
||||||
let split(url) = do
|
|
||||||
let split = url.splitN("?", 2)
|
|
||||||
if (split.length != 2) return {path: split[0], query: {}}
|
|
||||||
else return {path: split[0], query: decodeURLQuery(split[1])}
|
|
||||||
|
|
||||||
let queryStr(query) = do
|
|
||||||
let queryStr = []
|
|
||||||
let keys = query.keys()
|
|
||||||
for (i from 0 to keys.length) do
|
|
||||||
queryStr.append(encode(keys[i])+"="+encode(query[keys[i]]))
|
|
||||||
return queryStr.join("&")
|
|
||||||
|
|
||||||
|
|
||||||
let URL(url) = do
|
|
||||||
let protocol = null
|
|
||||||
let host = null
|
|
||||||
let port = null
|
|
||||||
let path = null
|
|
||||||
let query = null
|
|
||||||
let hash = null
|
|
||||||
let splitFunc = split
|
|
||||||
try do
|
|
||||||
let split = url.split("://")
|
|
||||||
if (split.length == 1) do
|
|
||||||
protocol = "http"
|
|
||||||
split = url.split("/")
|
|
||||||
if (split.length == 1) do
|
|
||||||
host = split[0]
|
|
||||||
path = "/"
|
|
||||||
else do
|
|
||||||
host = split[0]
|
|
||||||
path = "/"+split[1:].join("/")
|
|
||||||
else do
|
|
||||||
protocol = split[0]
|
|
||||||
split = split[1].split("/")
|
|
||||||
if (split.length == 1) do
|
|
||||||
host = split[0]
|
|
||||||
path = "/"
|
|
||||||
else do
|
|
||||||
host = split[0]
|
|
||||||
path = "/"+split[1:].join("/")
|
|
||||||
split = host.split(":")
|
|
||||||
if (split.length == 1) do
|
|
||||||
host = split[0]
|
|
||||||
if (protocol == "http") do
|
|
||||||
port = 80
|
|
||||||
else if (protocol == "https") do
|
|
||||||
port = 443
|
|
||||||
else do
|
|
||||||
host = split[0]
|
|
||||||
port = number(split[1:].join(":"))
|
|
||||||
split = path.split("#")
|
|
||||||
if (split.length == 1) do
|
|
||||||
path = split[0]
|
|
||||||
else do
|
|
||||||
path = split[0]
|
|
||||||
hash = split[1:].join("#")
|
|
||||||
let split = splitFunc(path)
|
|
||||||
path = split.path
|
|
||||||
query = split.query
|
|
||||||
return {protocol: protocol, host: host, port: port, path: path, query: query, hash: hash}
|
|
||||||
catch (e) do
|
|
||||||
return
|
|
||||||
Reference in new issue
Block a user