Skip to main content

encode_request

Function encode_request 

Source
pub fn encode_request(
    method: &str,
    path_with_query: &str,
    host: &str,
    headers: &[(String, String)],
    body: &[u8],
) -> Option<Vec<u8>>
Expand description

编码 HTTP/1.1 请求(代理转发上游)

输出布局:请求行 + Host + 透传头 + Content-Length + Connection: close + 空行 + body。

§参数

  • method:请求方法(RFC 7230 token,如 GET
  • path_with_query:路径 + 可选查询串(? 已拼接)
  • host:Host 头值(透传原始 Host)
  • headers:透传头;调用方负责剔除 host / connection / content-length 旧值
  • body:请求体(始终写 Content-Length,即使为 0)

§返回

  • Some(bytes):编码后的线格式字节
  • None:method/path/host/任一头名或头值含 \r / \n,或 method 非 token、 path/host 为空——fail-closed 整体拒绝,绝不静默放行或改写