XU XUv0.8.8
EN

API

#net/http

import: #net/http

counts: 19 函数, 46 方法, 8 类型, 0 常量, 0 方法集

HTTP/1.1 Client 与 Server、Header、Cookie。本包无 TLS。

struct Response

XuAPI
pub struct Response {
    pub status_code int
    pub status string
    pub headers string
    pub body string
    pub sticky string
}

用途

公开结构体 `Response`。

参数

status_code int
字段(int)
status string
字段(string)
headers string
字段(string)
body string
正文
sticky string
字段(string)

new_response

XuAPI
pub fn new_response() Response

用途

构造 response。

参数

无

返回

Response — 该类型的值

(Response) status_code

XuAPI
pub fn (r Response) status_code() int

用途

`Response` 上的方法:status码。

参数

r Response
接收者 Response(值接收者)

返回

int — 该类型的值

(Response) status

XuAPI
pub fn (r Response) status() string

用途

在 `Response` 上调用 `status`。

参数

r Response
接收者 Response(值接收者)

返回

string — 结果字符串

(Response) body

XuAPI
pub fn (r Response) body() string

用途

`Response` 上的方法:正文。

参数

r Response
接收者 Response(值接收者)

返回

string — 结果字符串

(Response) header

XuAPI
pub fn (r Response) header(name string) string

用途

`Response` 上的方法:头。

参数

r Response
接收者 Response(值接收者)
name string
名字(string)

返回

string — 结果字符串

struct Request

XuAPI
pub struct Request {
    pub method string
    pub path string
    pub headers string
    pub body string
    pub sticky string
}

用途

公开结构体 `Request`。

参数

method string
字段(string)
path string
文件系统路径
headers string
字段(string)
body string
正文
sticky string
字段(string)

new_request

XuAPI
pub fn new_request() Request

用途

构造 request。

参数

无

返回

Request — 该类型的值

(Request) method

XuAPI
pub fn (r Request) method() string

用途

在 `Request` 上调用 `method`。

参数

r Request
接收者 Request(值接收者)

返回

string — 结果字符串

(Request) path

XuAPI
pub fn (r Request) path() string

用途

在 `Request` 上调用 `path`。

参数

r Request
接收者 Request(值接收者)

返回

string — 结果字符串

(Request) body

XuAPI
pub fn (r Request) body() string

用途

`Request` 上的方法:正文。

参数

r Request
接收者 Request(值接收者)

返回

string — 结果字符串

(Request) header

XuAPI
pub fn (r Request) header(name string) string

用途

`Request` 上的方法:头。

参数

r Request
接收者 Request(值接收者)
name string
名字(string)

返回

string — 结果字符串

(Request) user_agent

XuAPI
pub fn (r Request) user_agent() string

用途

`Request` 上的方法:用户agent。

参数

r Request
接收者 Request(值接收者)

返回

string — 结果字符串

(Request) host

XuAPI
pub fn (r Request) host() string

用途

`Request` 上的方法:主机。

参数

r Request
接收者 Request(值接收者)

返回

string — 结果字符串

struct Server

XuAPI
pub struct Server {
    pub lfd int
}

用途

公开结构体 `Server`。

参数

lfd int
字段(int)

new_server

XuAPI
pub fn new_server() Server

用途

构造 server。

参数

无

返回

Server — 该类型的值

(&mut Server) listen

XuAPI
pub fn (s &mut Server) listen(addr string) int

用途

`&mut Server` 上的方法:开始监听。失败时 throw。

参数

s &mut Server
接收者 &mut Server(可变借用)
addr string
地址(string)

返回

int — 该类型的值

(Server) accept

XuAPI
pub fn (s Server) accept() int

用途

`Server` 上的方法:接受一个连接。失败时 throw。

参数

s Server
接收者 Server(值接收者)

返回

int — 该类型的值

(&mut Server) close

XuAPI
pub fn (s &mut Server) close() int

用途

`&mut Server` 上的方法:关闭资源。

参数

s &mut Server
接收者 &mut Server(可变借用)

返回

int — 该类型的值

status_text

XuAPI
pub fn status_text(code int) string

用途

status文本。

参数

code int
码(int)

返回

string — 结果字符串

(&mut Response) get

XuAPI
pub fn (r &mut Response) get(url string) int

用途

在 `&mut Response` 上调用 `get`。失败时 throw。

参数

r &mut Response
接收者 &mut Response(可变借用)
url string
url(string)

返回

int — 该类型的值

(&mut Response) post

XuAPI
pub fn (r &mut Response) post(url string, body &string) int

用途

在 `&mut Response` 上调用 `post`。失败时 throw。

参数

r &mut Response
接收者 &mut Response(可变借用)
url string
url(string)
body &string
正文(借用,调用方仍持有;类型 &string)

返回

int — 该类型的值

(Response) cookies

XuAPI
pub fn (r Response) cookies() []Cookie

用途

在 `Response` 上调用 `cookies`。

参数

r Response
接收者 Response(值接收者)

返回

[]Cookie — 切片结果

struct Client

XuAPI
pub struct Client {
    pub jar cookiejar.Jar
    pub jar_on int
    pub timeout_ns int
    pub max_redirects int
}

用途

公开结构体 `Client`。

参数

jar cookiejar.Jar
字段(cookiejar.Jar)
jar_on int
字段(int)
timeout_ns int
超时(纳秒)
max_redirects int
字段(int)

new_client

XuAPI
pub fn new_client() Client

用途

构造 client。

参数

无

返回

Client — 该类型的值

(&mut Client) set_jar

XuAPI
pub fn (c &mut Client) set_jar(j cookiejar.Jar)

用途

`&mut Client` 上的方法:设置 jar。

参数

c &mut Client
接收者 &mut Client(可变借用)
j cookiejar.Jar
下标(cookiejar.Jar)

(&mut Client) set_timeout

XuAPI
pub fn (c &mut Client) set_timeout(ns int)

用途

`&mut Client` 上的方法:设置 timeout。

参数

c &mut Client
接收者 &mut Client(可变借用)
ns int
ns(int)

(&mut Client) do

XuAPI
pub fn (c &mut Client) do(method string, raw_url string, body &string) Response

用途

`&mut Client` 上的方法:执行一次。失败时 throw。

参数

c &mut Client
接收者 &mut Client(可变借用)
method string
method(string)
raw_url string
raw_url(string)
body &string
正文(借用,调用方仍持有;类型 &string)

返回

Response — 该类型的值

(&mut Client) get

XuAPI
pub fn (c &mut Client) get(raw_url string) Response

用途

在 `&mut Client` 上调用 `get`。失败时 throw。

参数

c &mut Client
接收者 &mut Client(可变借用)
raw_url string
raw_url(string)

返回

Response — 该类型的值

(&mut Client) post

XuAPI
pub fn (c &mut Client) post(raw_url string, body &string) Response

用途

在 `&mut Client` 上调用 `post`。失败时 throw。

参数

c &mut Client
接收者 &mut Client(可变借用)
raw_url string
raw_url(string)
body &string
正文(借用,调用方仍持有;类型 &string)

返回

Response — 该类型的值

(&mut Request) read

XuAPI
pub fn (req &mut Request) read(fd int) int

用途

`&mut Request` 上的方法:读出最多 max 字节。失败时 throw。

参数

req &mut Request
接收者 &mut Request(可变借用)
fd int
文件描述符(int)

返回

int — 该类型的值

write_response

XuAPI
pub fn write_response(fd int, status_code int, body &string) int

用途

写入响应。失败时 throw。

参数

fd int
文件描述符(int)
status_code int
status_code(int)
body &string
正文(借用,调用方仍持有;类型 &string)

返回

int — 该类型的值

write

XuAPI
pub fn write(fd int, status_code int, content_type string, body &string) int

用途

写入数据,返回写入的字节数。

参数

fd int
文件描述符(int)
status_code int
status_code(int)
content_type string
content_type(string)
body &string
正文(借用,调用方仍持有;类型 &string)

返回

int — 写入的字节数

(&Client) has_idle_connection

XuAPI
pub fn (c &Client) has_idle_connection() bool

用途

`&Client` 上的方法:判断是否具有 idle connection。

参数

c &Client
接收者 &Client(借用)

返回

bool — 是否成立

struct Context

XuAPI
pub struct Context {
    pub fd int
    pub req Request
}

用途

公开结构体 `Context`。

参数

fd int
文件描述符
req Request
字段(Request)

(Context) method

XuAPI
pub fn (c Context) method() string

用途

在 `Context` 上调用 `method`。

参数

c Context
接收者 Context(值接收者)

返回

string — 结果字符串

(Context) raw_path

XuAPI
pub fn (c Context) raw_path() string

用途

`Context` 上的方法:rawpath。

参数

c Context
接收者 Context(值接收者)

返回

string — 结果字符串

(Context) path

XuAPI
pub fn (c Context) path() string

用途

在 `Context` 上调用 `path`。

参数

c Context
接收者 Context(值接收者)

返回

string — 结果字符串

(Context) query

XuAPI
pub fn (c Context) query() string

用途

`Context` 上的方法:查询串。

参数

c Context
接收者 Context(值接收者)

返回

string — 结果字符串

(Context) header

XuAPI
pub fn (c Context) header(name string) string

用途

`Context` 上的方法:头。

参数

c Context
接收者 Context(值接收者)
name string
名字(string)

返回

string — 结果字符串

(Context) body

XuAPI
pub fn (c Context) body() string

用途

`Context` 上的方法:正文。

参数

c Context
接收者 Context(值接收者)

返回

string — 结果字符串

(Context) text

XuAPI
pub fn (c Context) text(status int, body string) int

用途

`Context` 上的方法:返回当前文本。失败时 throw。

参数

c Context
接收者 Context(值接收者)
status int
status(int)
body string
正文(string)

返回

int — 该类型的值

(Context) text_extra

XuAPI
pub fn (c Context) text_extra(status int, extra string, body string) int

用途

`Context` 上的方法:文本extra。失败时 throw。

参数

c Context
接收者 Context(值接收者)
status int
status(int)
extra string
extra(string)
body string
正文(string)

返回

int — 该类型的值

(Context) html

XuAPI
pub fn (c Context) html(status int, body string) int

用途

`Context` 上的方法:HTML。失败时 throw。

参数

c Context
接收者 Context(值接收者)
status int
status(int)
body string
正文(string)

返回

int — 该类型的值

(Context) bytes

XuAPI
pub fn (c Context) bytes(status int, content_type string, body string) int

用途

`Context` 上的方法:返回已缓冲的字节串。失败时 throw。

参数

c Context
接收者 Context(值接收者)
status int
status(int)
content_type string
content_type(string)
body string
正文(string)

返回

int — 该类型的值

(Server) serve

XuAPI
pub fn (s Server) serve(handle fn(Context)) int

用途

在 `Server` 上调用 `serve`。

参数

s Server
接收者 Server(值接收者)
handle fn(Context)
handle(函数值;类型 fn(Context))

返回

int — 该类型的值

listen_and_serve_handler

XuAPI
pub fn listen_and_serve_handler(addr string, handle fn(Context)) int

用途

监听andservehandler。失败时 throw。

参数

addr string
地址(string)
handle fn(Context)
handle(函数值;类型 fn(Context))

返回

int — 该类型的值

(Request) cookies

XuAPI
pub fn (r Request) cookies() []Cookie

用途

在 `Request` 上调用 `cookies`。

参数

r Request
接收者 Request(值接收者)

返回

[]Cookie — 切片结果

struct FileServer

XuAPI
pub struct FileServer {
    pub root string
}

用途

公开结构体 `FileServer`。

参数

root string
字段(string)

file_server

XuAPI
pub fn file_server(root string) FileServer

用途

文件服务端。

参数

root string
root(string)

返回

FileServer — 该类型的值

listen_and_serve

XuAPI
pub fn listen_and_serve(addr string, root string) int

用途

监听andserve。失败时 throw。

参数

addr string
地址(string)
root string
root(string)

返回

int — 该类型的值

(FileServer) serve

XuAPI
pub fn (fs FileServer) serve(fd int)

用途

在 `FileServer` 上调用 `serve`。

参数

fs FileServer
接收者 FileServer(值接收者)
fd int
文件描述符(int)

serve_file

XuAPI
pub fn serve_file(fd int, name string) int

用途

serve文件。失败时 throw。

参数

fd int
文件描述符(int)
name string
名字(string)

返回

int — 该类型的值

struct Header

XuAPI
pub struct Header {
    pub keys []string
    pub vals []string
}

用途

公开结构体 `Header`。

参数

keys []string
字段([]string)
vals []string
字段([]string)

new_header

XuAPI
pub fn new_header() Header

用途

构造 header。

参数

无

返回

Header — 该类型的值

canonical_header_key

XuAPI
pub fn canonical_header_key(s &string) string

用途

canonical头键。

参数

s &string
源字符串(借用,调用方仍持有;类型 &string)

返回

string — 结果字符串

(&mut Header) add

XuAPI
pub fn (h &mut Header) add(key &string, value &string)

用途

`&mut Header` 上的方法:相加。

参数

h &mut Header
接收者 &mut Header(可变借用)
key &string
键(借用,调用方仍持有;类型 &string)
value &string
value(借用,调用方仍持有;类型 &string)

(&mut Header) del

XuAPI
pub fn (h &mut Header) del(key &string)

用途

在 `&mut Header` 上调用 `del`。

参数

h &mut Header
接收者 &mut Header(可变借用)
key &string
键(借用,调用方仍持有;类型 &string)

(&mut Header) set

XuAPI
pub fn (h &mut Header) set(key &string, value &string)

用途

在 `&mut Header` 上调用 `set`。

参数

h &mut Header
接收者 &mut Header(可变借用)
key &string
键(借用,调用方仍持有;类型 &string)
value &string
value(借用,调用方仍持有;类型 &string)

(Header) get

XuAPI
pub fn (h Header) get(key &string) string

用途

在 `Header` 上调用 `get`。

参数

h Header
接收者 Header(值接收者)
key &string
键(借用,调用方仍持有;类型 &string)

返回

string — 结果字符串

(Header) values

XuAPI
pub fn (h Header) values(key &string) []string

用途

在 `Header` 上调用 `values`。

参数

h Header
接收者 Header(值接收者)
key &string
键(借用,调用方仍持有;类型 &string)

返回

[]string — 切片结果

(Header) clone

XuAPI
pub fn (h Header) clone() Header

用途

`Header` 上的方法:拷贝一份独立的 string。

参数

h Header
接收者 Header(值接收者)

返回

Header — 该类型的值

(Header) len

XuAPI
pub fn (h Header) len() int

用途

`Header` 上的方法:返回长度。

参数

h Header
接收者 Header(值接收者)

返回

int — 该类型的值

(Header) write

XuAPI
pub fn (h Header) write() string

用途

`Header` 上的方法:写入数据,返回写入的字节数。

参数

h Header
接收者 Header(值接收者)

返回

string — 结果字符串

parse_header

XuAPI
pub fn parse_header(raw &string) Header

用途

解析为 header。

参数

raw &string
raw(借用,调用方仍持有;类型 &string)

返回

Header — 该类型的值

(Response) reusable

XuAPI
pub fn (r Response) reusable(method string) bool

用途

在 `Response` 上调用 `reusable`。

参数

r Response
接收者 Response(值接收者)
method string
method(string)

返回

bool — 是否成立

read_response

XuAPI
pub fn read_response(fd int, method string) Response

用途

读取响应。失败时 throw。

参数

fd int
文件描述符(int)
method string
method(string)

返回

Response — 该类型的值

detect_content_type

XuAPI
pub fn detect_content_type(data &string) string

用途

detectcontenttype。

参数

data &string
数据(借用,调用方仍持有;类型 &string)

返回

string — 结果字符串