diff --git a/vlib/net/http/request.v b/vlib/net/http/request.v index 927cc02414dda2..08fda91a9c3170 100644 --- a/vlib/net/http/request.v +++ b/vlib/net/http/request.v @@ -49,9 +49,23 @@ pub mut: on_finish RequestFinishFn = unsafe { nil } } +// free frees the memory allocated for the request @[unsafe] pub fn (mut req Request) free() { unsafe { req.header.free() } + unsafe { req.host.free() } + // TODO: make the cookies stored in a cookie jar, + // that owns them, so that they can be used by many requests. + // TODO: `unsafe { req.cookie.free() }` is a cgen error; it should be a checker one instead, since cookie is a method... + unsafe { req.cookies.free() } + unsafe { req.data.free() } + unsafe { req.url.free() } + // TODO: the user agent can be shared between many requests too, just like verify, cert and cert_key + unsafe { req.user_agent.free() } + unsafe { req.verify.free() } + unsafe { req.cert.free() } + unsafe { req.cert_key.free() } + // Note: proxy is not owned by the request; it is intended to be used for many requests } // add_header adds the key and value of an HTTP request header diff --git a/vlib/net/http/response.v b/vlib/net/http/response.v index 6a59d6777c82b4..69cb020df739e6 100644 --- a/vlib/net/http/response.v +++ b/vlib/net/http/response.v @@ -16,9 +16,13 @@ pub mut: http_version string } +// free frees the memory allocated for the http response @[unsafe] pub fn (mut resp Response) free() { + unsafe { resp.body.free() } unsafe { resp.header.free() } + unsafe { resp.status_msg.free() } + unsafe { resp.http_version.free() } } // Formats resp to bytes suitable for HTTP response transmission