Skip to content

Commit

Permalink
Merge branch 'main' into concurrent-weak
Browse files Browse the repository at this point in the history
  • Loading branch information
toots authored Mar 25, 2024
2 parents d75921b + 3043b9f commit 35e6841
Show file tree
Hide file tree
Showing 50 changed files with 887 additions and 860 deletions.
166 changes: 83 additions & 83 deletions tests/harbor/http.liq
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
def f() =
# Default response
def handler(req, _) =
test.equals(req.http_version, "1.1")
test.equals(req.method, "GET")
test.equals(req.body(timeout=5.0), "")
test.equals(req.query, [])
test.equals(req.path, "/default")
test.equal(req.http_version, "1.1")
test.equal(req.method, "GET")
test.equal(req.body(timeout=5.0), "")
test.equal(req.query, [])
test.equal(req.path, "/default")
end

harbor.http.register("/default", port=3456, handler)
resp = http.get("http://localhost:3456/default")
test.equals(resp.status_message, "OK")
test.equals(resp.status_code, 200)
test.equals(resp.http_version, "1.1")
test.equals(resp.headers, [])
test.equals("#{resp}", "")
test.equal(resp.status_message, "OK")
test.equal(resp.status_code, 200)
test.equal(resp.http_version, "1.1")
test.equal(resp.headers, [])
test.equal("#{resp}", "")

# Endpoint are executed in the order they are declared
def handler(_, _) =
Expand All @@ -24,39 +24,39 @@ def f() =
harbor.http.register.regexp(r/default/g, port=3456, handler)
harbor.http.register("/default", port=3456, handler)
resp = http.get("http://localhost:3456/default")
test.equals(resp.status_message, "OK")
test.equals(resp.status_code, 200)
test.equals(resp.http_version, "1.1")
test.equals(resp.headers, [])
test.equals("#{resp}", "")
test.equal(resp.status_message, "OK")
test.equal(resp.status_code, 200)
test.equal(resp.http_version, "1.1")
test.equal(resp.headers, [])
test.equal("#{resp}", "")

# String response with matches
def handler(req, _) =
test.equals(req.http_version, "1.1")
test.equals(req.method, "GET")
test.equals(req.body(timeout=5.0), "")
test.equals(req.query, [("bla", "blo"), ("gni", "gno")])
test.equals(req.path, "/path/gno/blo")
test.equal(req.http_version, "1.1")
test.equal(req.method, "GET")
test.equal(req.body(timeout=5.0), "")
test.equal(req.query, [("bla", "blo"), ("gni", "gno")])
test.equal(req.path, "/path/gno/blo")
end

harbor.http.register("/path/:gni/:bla", port=3456, handler)
resp = http.get("http://localhost:3456/path/gno/blo")
test.equals(resp.status_message, "OK")
test.equals(resp.status_code, 200)
test.equals(resp.http_version, "1.1")
test.equals(resp.headers, [])
test.equals("#{resp}", "")
test.equal(resp.status_message, "OK")
test.equal(resp.status_code, 200)
test.equal(resp.http_version, "1.1")
test.equal(resp.headers, [])
test.equal("#{resp}", "")

# Full query
def handler(req, res) =
test.equals(req.http_version, "1.0")
test.equals(req.method, "POST")
test.equals(
test.equal(req.http_version, "1.0")
test.equal(req.method, "POST")
test.equal(
req.query,
[("bla", "in"), ("foo", "with"), ("gnu", "gno"), ("gni", "gno")]
)

test.equals(
test.equal(
req.headers,
[
("host", "localhost:3456"),
Expand All @@ -68,8 +68,8 @@ def f() =
]
)

test.equals(req.path, "/some/path/with/full/in/it")
test.equals(req.body(timeout=5.0), "foobarlol")
test.equal(req.path, "/some/path/with/full/in/it")
test.equal(req.body(timeout=5.0), "foobarlol")
res.status_code(201)
res.status_message("YYR")
res.http_version("1.0")
Expand Down Expand Up @@ -103,10 +103,10 @@ def f() =
"http://localhost:3456/some/path/with/full/in/it?gni=gno&gnu=gno"
)

test.equals(resp.status_message, "YYR")
test.equals(resp.status_code, 201)
test.equals(resp.http_version, "1.0")
test.equals(
test.equal(resp.status_message, "YYR")
test.equal(resp.status_code, 201)
test.equal(resp.http_version, "1.0")
test.equal(
resp.headers,
[
("some", "value"),
Expand All @@ -115,14 +115,14 @@ def f() =
]
)

test.equals("#{resp}", "gnignognignognignognigno")
test.equal("#{resp}", "gnignognignognignognigno")

# Large non-chunked query
def handler(req, _) =
test.equals(req.http_version, "1.1")
test.equals(req.method, "POST")
test.equals(req.query, [])
test.equals(
test.equal(req.http_version, "1.1")
test.equal(req.method, "POST")
test.equal(req.query, [])
test.equal(
req.headers,
[
("host", "localhost:3456"),
Expand All @@ -133,8 +133,8 @@ def f() =
]
)

test.equals(req.path, "/large_non_chunked")
test.equals(string.length(req.body(timeout=5.0)), 10_000)
test.equal(req.path, "/large_non_chunked")
test.equal(string.length(req.body(timeout=5.0)), 10_000)
end

harbor.http.register("/large_non_chunked", method="POST", port=3456, handler)
Expand All @@ -143,18 +143,18 @@ def f() =
data=string.make(10_000), "http://localhost:3456/large_non_chunked"
)

test.equals(resp.status_message, "OK")
test.equals(resp.status_code, 200)
test.equals(resp.http_version, "1.1")
test.equals(resp.headers, [])
test.equals("#{resp}", "")
test.equal(resp.status_message, "OK")
test.equal(resp.status_code, 200)
test.equal(resp.http_version, "1.1")
test.equal(resp.headers, [])
test.equal("#{resp}", "")

# Chunked query
def handler(req, res) =
test.equals(req.http_version, "1.1")
test.equals(req.method, "POST")
test.equals(req.query, [])
test.equals(
test.equal(req.http_version, "1.1")
test.equal(req.method, "POST")
test.equal(req.query, [])
test.equal(
req.headers,
[
("host", "localhost:3456"),
Expand All @@ -166,8 +166,8 @@ def f() =
]
)

test.equals(req.path, "/chunked")
test.equals(req.body(timeout=5.0), "foobarlol")
test.equal(req.path, "/chunked")
test.equal(req.body(timeout=5.0), "foobarlol")
end

harbor.http.register("/chunked", method="POST", port=3456, handler)
Expand All @@ -186,18 +186,18 @@ def f() =
end

resp = http.post(data=data, "http://localhost:3456/chunked")
test.equals(resp.status_message, "OK")
test.equals(resp.status_code, 200)
test.equals(resp.http_version, "1.1")
test.equals(resp.headers, [])
test.equals("#{resp}", "")
test.equal(resp.status_message, "OK")
test.equal(resp.status_code, 200)
test.equal(resp.http_version, "1.1")
test.equal(resp.headers, [])
test.equal("#{resp}", "")

# Large chunked query
def handler(req, res) =
test.equals(req.http_version, "1.1")
test.equals(req.method, "POST")
test.equals(req.query, [])
test.equals(
test.equal(req.http_version, "1.1")
test.equal(req.method, "POST")
test.equal(req.query, [])
test.equal(
req.headers,
[
("host", "localhost:3456"),
Expand All @@ -209,14 +209,14 @@ def f() =
]
)

test.equals(req.path, "/large_chunked")
test.equal(req.path, "/large_chunked")

def rec f(count) =
ret = req.data()
if ret != "" then f(count + string.length(ret)) else count end
end

test.equals(f(0), 10_000_000)
test.equal(f(0), 10_000_000)
end

harbor.http.register("/large_chunked", method="POST", port=3456, handler)
Expand All @@ -237,11 +237,11 @@ def f() =

# Custom response
def handler(req) =
test.equals(req.http_version, "1.1")
test.equals(req.method, "GET")
test.equals(req.data(), "")
test.equals(req.query, [])
test.equals(req.path, "/custom")
test.equal(req.http_version, "1.1")
test.equal(req.method, "GET")
test.equal(req.data(), "")
test.equal(req.query, [])
test.equal(req.path, "/custom")
req.socket.write(
"HTTP/1.0 201 YYR\r\nFoo: bar\r\n\r\n"
)
Expand All @@ -251,24 +251,24 @@ def f() =

harbor.http.register.simple("/custom", port=3456, handler)
resp = http.get("http://localhost:3456/custom")
test.equals(resp.status_message, "YYR")
test.equals(resp.status_code, 201)
test.equals(resp.http_version, "1.0")
test.equals(resp.headers, [("foo", "bar")])
test.equals("#{resp}", "")
test.equal(resp.status_message, "YYR")
test.equal(resp.status_code, 201)
test.equal(resp.http_version, "1.0")
test.equal(resp.headers, [("foo", "bar")])
test.equal("#{resp}", "")

# Cors headers
harbor.http.middleware.register(harbor.http.middleware.cors(origin="foo.com"))
resp = http.get("http://localhost:3456/default")
test.equals(resp.status_message, "OK")
test.equals(resp.http_version, "1.1")
test.equals(resp.status_code, 200)
test.equals(
test.equal(resp.status_message, "OK")
test.equal(resp.http_version, "1.1")
test.equal(resp.status_code, 200)
test.equal(
resp.headers,
[("access-control-allow-origin", "foo.com"), ("vary", "Origin")]
)

test.equals("#{resp}", "")
test.equal("#{resp}", "")

# transport conflict
transport = http.transport.ssl(certificate="foo", key="bla")
Expand All @@ -279,7 +279,7 @@ def f() =

test.fail()
catch err : [error.http] do
test.equals(
test.equal(
err.message,
"Port is already opened with a different transport"
)
Expand All @@ -294,14 +294,14 @@ def f() =

harbor.http.register("/response_ended", port=3456, handler)
resp = http.get("http://localhost:3456/response_ended")
test.equals(resp.status_message, "OK")
test.equals(resp.status_code, 200)
test.equal(resp.status_message, "OK")
test.equal(resp.status_code, 200)
try
fn = read()
fn(timeout=10.)
test.fail()
catch err : [error.http] do
test.equals(
test.equal(
err.message,
"Response ended!"
)
Expand Down
Loading

0 comments on commit 35e6841

Please sign in to comment.