helper for status codes

This commit is contained in:
nixo 2020-10-23 19:36:45 +02:00
parent 0f587b3464
commit ba05db91fe
2 changed files with 18 additions and 10 deletions

View File

@ -8,15 +8,7 @@ include("types.jl")
include("server.jl")
import Base.write
write(c::Connection, data::Vector{UInt8}) = OpenSSL.write(c.client, data)
function write(conn::Connection, s::Status)
write(conn.client,
string(s.major, s.minor, ' ', s.meta, '\r', '\n'))
end
function write(conn::Connection, r::Response)
write(conn, r.status)
write(conn.client, r.body)
end
include("rw.jl")
export link, document, status, not_found
end # module

16
src/rw.jl Normal file
View File

@ -0,0 +1,16 @@
import Base.write
write(c::Connection, data::Vector{UInt8}) = OpenSSL.write(c.client, data)
function write(conn::Connection, s::Status)
write(conn.client,
string(s.major, s.minor, ' ', s.meta, '\r', '\n'))
end
function write(conn::Connection, r::Response)
write(conn, r.status)
write(conn.client, r.body)
end
status(conn::Connection, s...) = write(conn, Status(s...))
not_found(conn::Connection, meta = "Not Found") = status(conn, 51, meta)
document(conn::Connection, body) =
write(conn, Response(Status(20, "text/gemini"), body))
link(dst, name = dst) = string("=> ", dst, " ", name)