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

vweb: continue after bad http client connection; performance fixes

* Enable compiling vweb with -prod (by supressing 'declared and not used' warning about 'reset') .

* Fix http responses (now wrk is happy and shows no errors) by adding a Content-Length header.

* Fix -g compilation for urllib.v .

* vweb: println action= only in debug mode.

* vweb: max request headers counting fix.

* Make vweb.html get a 'ctx mut Context' param, just like the other methods.

* vweb: simplify add_header.

* Use a string builder for the most common html case so that the response http text can be send in one go.

* vweb: reduce _STR/string interpolation usage in the most common html response case.

* vweb: refactor common http response formatting into Context.send_response_to_client/2 method.
This commit is contained in:
Delyan Angelov
2019-12-11 16:32:54 +02:00
committed by Alexander Medvednikov
parent cfeec92826
commit 13769f440f
8 changed files with 85 additions and 56 deletions

View File

@@ -202,13 +202,23 @@ pub fn dial(address string, port int) ?Socket {
return s
}
// send string data to socket
// send data to socket (when you have a memory buffer)
pub fn (s Socket) send(buf byteptr, len int) ?int {
res := C.send(s.sockfd, buf, len, MSG_NOSIGNAL)
if res < 0 {
return error('net.send: failed with $res')
mut dptr := buf
mut dlen := len
for {
sbytes := C.send(s.sockfd, dptr, dlen, MSG_NOSIGNAL)
if sbytes < 0 { return error('net.send: failed with $sbytes') }
dlen -= sbytes
if dlen <= 0 { break }
dptr += sbytes
}
return res
return len
}
// send string data to socket (when you have a v string)
pub fn (s Socket) send_string(sdata string) ?int {
return s.send( sdata.str, sdata.len )
}
// receive string data from socket

View File

@@ -518,8 +518,8 @@ fn parse_url(rawurl string, via_request bool) ?URL {
// RFC 3986, §3.3:
// In addition, a URI reference (Section 4.1) may be a relative-path reference,
// in which case the first path segment cannot contain a colon (':') character.
colon := rest.index(':') or { -1 }
slash := rest.index('/') or { -1 }
colon := rest.index(':') or { return error('there should be a : in the URL') }
slash := rest.index('/') or { return error('there should be a / in the URL') }
if colon >= 0 && (slash < 0 || colon < slash) {
// First path segment has colon. Not allowed in relative URL.
return error(error_msg('parse_url: first path segment in URL cannot contain colon', ''))
@@ -553,7 +553,7 @@ struct ParseAuthorityRes {
fn parse_authority(authority string) ?ParseAuthorityRes {
i := authority.last_index('@')
mut host := ''
mut user := user('')
mut zuser := user('')
if i < 0 {
h := parse_host(authority) or {
return error(err)
@@ -566,7 +566,7 @@ fn parse_authority(authority string) ?ParseAuthorityRes {
host = h
}
if i < 0 {
return ParseAuthorityRes{host: host, user: user}
return ParseAuthorityRes{host: host, user: zuser}
}
mut userinfo := authority[..i]
if !valid_userinfo(userinfo) {
@@ -577,7 +577,7 @@ fn parse_authority(authority string) ?ParseAuthorityRes {
return error(err)
}
userinfo = u
user = user(userinfo)
zuser = user(userinfo)
} else {
mut username, mut password := split(userinfo, `:`, true)
u := unescape(username, .encode_user_password) or {
@@ -588,10 +588,10 @@ fn parse_authority(authority string) ?ParseAuthorityRes {
return error(err)
}
password = p
user = user_password(username, password)
zuser = user_password(username, password)
}
return ParseAuthorityRes{
user: user
user: zuser
host: host
}
}