最美情侣中文字幕电影,在线麻豆精品传媒,在线网站高清黄,久久黄色视频

歡迎光臨散文網(wǎng) 會(huì)員登陸 & 注冊(cè)

[rust] 將合法http字符串切片轉(zhuǎn)換為hyper::Request結(jié)構(gòu)的方法

2023-08-08 22:13 作者:信天鴿  | 我要投稿

/// use to covert **valid** http str to `hyper::Request`
///
/// example
/// ```rust
/// let listener = TcpListener::bind("localhost:8080").unwrap();
/// ? ?for stream in listener.incoming() {
/// ? ? ? ?let mut stream = stream.unwrap();
/// ? ? ? ?let mut buffer = String::new();
/// ? ? ? ?stream.read_to_string(&mut buffer).unwrap();
/// ? ? ? ?let req = covert_str_to_request(buffer.as_str());
/// ? ? ? ?println!("{req:#?}");
/// ? ?}
/// ```
fn covert_str_to_request(s: &str) -> hyper::Request<Option<&str>> {
? ?let mut lines = s.lines();
? ?let line = lines.next().expect("");
? ?let mut line_attrs = line.split(' ');
? ?let mut builder = hyper::Request::builder();
? ?if let Some(attr) = line_attrs.next() {
? ? ? ?builder = builder.method(hyper::Method::from_str(attr).expect("expect in setting method"));
? ?}
? ?if let Some(attr) = line_attrs.next() {
? ? ? ?builder = builder.uri(attr);
? ?}
? ?if let Some(attr) = line_attrs.next() {
? ? ? ?builder = builder.version(match attr {
? ? ? ? ? ?"HTTP/0.9" => hyper::Version::HTTP_09,
? ? ? ? ? ?"HTTP/1.0" => hyper::Version::HTTP_10,
? ? ? ? ? ?"HTTP/2.0" => hyper::Version::HTTP_2,
? ? ? ? ? ?"HTTP/3.0" => hyper::Version::HTTP_3,
? ? ? ? ? ?_ => hyper::Version::default()
? ? ? ?});
? ?}
? ?while let Some(line) = lines.next() {
? ? ? ?if line.is_empty() {
? ? ? ? ? ?break;
? ? ? ?}
? ? ? ?let pair = line.split_once(':').expect("");
? ? ? ?builder = builder.header(pair.0, pair.1);
? ?}
? ?if let Some(body_str) = lines.next() {
? ? ? ?builder.body(Some(body_str)).expect("")
? ?} else {
? ? ? ?builder.body(None).expect("")
? ?}
}

[rust] 將合法http字符串切片轉(zhuǎn)換為hyper::Request結(jié)構(gòu)的方法的評(píng)論 (共 條)

分享到微博請(qǐng)遵守國(guó)家法律
福清市| 靖宇县| 丹寨县| 邵武市| 林芝县| 揭西县| 沾益县| 攀枝花市| 磐石市| 石阡县| 错那县| 崇文区| 兰溪市| 渑池县| 定远县| 兴化市| 紫金县| 西藏| 寿宁县| 舞钢市| 论坛| 徐闻县| 天峻县| 苍南县| 靖远县| 新闻| 平阴县| 天全县| 桐梓县| 柯坪县| 阿尔山市| 黎川县| 泌阳县| 邢台县| 宣武区| 华蓥市| 怀化市| 宣恩县| 长宁县| 大足县| 资溪县|