1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

vweb: use http.Response constants instead of strings (#10730)

This commit is contained in:
Miccah
2021-07-10 03:58:07 -05:00
committed by GitHub
parent cb14e42af8
commit 44e78a6301
2 changed files with 73 additions and 17 deletions

View File

@@ -22,10 +22,15 @@ fn (mut resp Response) free() {
// Formats resp to bytes suitable for HTTP response transmission
pub fn (resp Response) bytes() []byte {
// TODO: build []byte directly; this uses two allocations
return resp.bytestr().bytes()
}
// Formats resp to a string suitable for HTTP response transmission
pub fn (resp Response) bytestr() string {
// TODO: cookies
return ('$resp.version $resp.status_code ${status_from_int(resp.status_code).str()}\r\n' + '${resp.header.render(
version: resp.version
)}\r\n' + '$resp.text').bytes()
)}\r\n' + '$resp.text')
}
// Parse a raw HTTP response into a Response object