blob: 6ea1453b992b15147c764ece446659824c5bed12 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
// Copyright (C) 2021-2021 The Whirlsplash Collective
// SPDX-License-Identifier: GPL-3.0-only
use std::str::from_utf8;
use actix_web::{HttpRequest, HttpResponse};
// error: this argument is passed by value, but not consumed in the function
// body
#[allow(clippy::needless_pass_by_value)]
pub fn info(req: HttpRequest) -> HttpResponse {
let mut easy = curl::easy::Easy::new();
easy
.url(&format!(
"http://www-dynamic.us.worlds.net/cgi-bin/profile.pl?{}",
qstring::QString::from(req.query_string())
.get("username")
.unwrap_or(""),
))
.unwrap();
let mut response = Vec::new();
// https://docs.rs/curl/0.4.6/curl/easy/struct.Easy.html
{
let mut transfer = easy.transfer();
transfer
.write_function(|data| {
response.extend_from_slice(data);
Ok(data.len())
})
.unwrap();
transfer.perform().unwrap();
}
HttpResponse::Ok().body(from_utf8(&response).unwrap().to_string())
}
|