#net/http/httptest
Xu 0.16.0 API
import: #net/http/httptest
counts: 3 functions, 7 methods, 2 types, 0 constants, 0 method sets
In-process ResponseRecorder and test Request. No real listen.
struct ResponseRecorder
pub struct ResponseRecorder {
pub code int
pub hdr string
pub body string
pub wrote int
}
Purpose
Structure encapsulating code, hdr, body, wrote.
Public fields
code int- code
hdr string- field (string)
body string- body
wrote int- field (int)
new_recorder
pub fn new_recorder() ResponseRecorder
Purpose
Construct recorder.
Parameters
No arguments are required.
Returns
ResponseRecorder — a value of this type
($&ResponseRecorder) write
pub fn (r $&ResponseRecorder) write(b &string) int
Purpose
Operation on $&ResponseRecorder: write data and return the byte count.
Parameters
r $&ResponseRecorder- The
ResponseRecorder instance used by this call (exclusive borrow).
b &string- b (read-only borrow; caller keeps the original; type &string)
Returns
int — bytes written
(ResponseRecorder) result_code
pub fn (r ResponseRecorder) result_code() int
Purpose
Operation on ResponseRecorder: result code.
Parameters
r ResponseRecorder- The
ResponseRecorder instance used by this call (value receiver).
Returns
int — a value of this type
(ResponseRecorder) result_body
pub fn (r ResponseRecorder) result_body() string
Purpose
Operation on ResponseRecorder: result body.
Parameters
r ResponseRecorder- The
ResponseRecorder instance used by this call (value receiver).
Returns
string — result string
struct Server
pub struct Server {
pub url string
pub addr string
pub lfd int
}
Purpose
Structure encapsulating url, addr, lfd.
Public fields
url string- field (string)
addr string- address
lfd int- field (int)
new_server
pub fn new_server(handle fn(http.Context)) Server
Purpose
Construct server. Throws on failure; handle the error or propagate it to the caller.
Parameters
handle fn(http.Context)- handle (function value; type fn(http.Context))
Returns
Server — a value of this type
($&Server) close
pub fn (s $&Server) close() int
Purpose
Operation on $&Server: close the resource.
Parameters
s $&Server- The
Server instance used by this call (exclusive borrow).
Returns
int — a value of this type
new_request
pub fn new_request(method string, target string, body string) http.Request
Purpose
Construct request.
Parameters
method string- method (string)
target string- target (string)
body string- body (string)
Returns
http.Request — a value of this type