XU XUv0.16.0

#net/http/httptest

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

XuAPI
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

XuAPI
pub fn new_recorder() ResponseRecorder

Purpose

Construct recorder.

Parameters

No arguments are required.

Returns

ResponseRecorder — a value of this type

($&ResponseRecorder) write_header

XuAPI
pub fn (r $&ResponseRecorder) write_header(code int)

Purpose

Operation on $&ResponseRecorder: write header.

Parameters

r $&ResponseRecorder
The ResponseRecorder instance used by this call (exclusive borrow).
code int
code (int)

Returns

This call does not return a value.

($&ResponseRecorder) header_set

XuAPI
pub fn (r $&ResponseRecorder) header_set(key string, val string)

Purpose

Operation on $&ResponseRecorder: header set.

Parameters

r $&ResponseRecorder
The ResponseRecorder instance used by this call (exclusive borrow).
key string
key (string)
val string
value (string)

Returns

This call does not return a value.

($&ResponseRecorder) write

XuAPI
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

XuAPI
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

XuAPI
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

(ResponseRecorder) result_header

XuAPI
pub fn (r ResponseRecorder) result_header(name string) string

Purpose

Operation on ResponseRecorder: result header.

Parameters

r ResponseRecorder
The ResponseRecorder instance used by this call (value receiver).
name string
name (string)

Returns

string — result string

struct Server

XuAPI
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

XuAPI
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

XuAPI
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

XuAPI
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