Skip to content

Commit

Permalink
ci: fix report-missing-fn-doc job failure, free more stuff in the man…
Browse files Browse the repository at this point in the history
…ual free() methods for http request/response
  • Loading branch information
spytheman committed Dec 10, 2023
1 parent 0b3d8e3 commit 0c214db
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
14 changes: 14 additions & 0 deletions vlib/net/http/request.v
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions vlib/net/http/response.v
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 0c214db

Please sign in to comment.