From e0e0bdbc3aa2d8b35a69616acd169e0cba978d6d Mon Sep 17 00:00:00 2001 From: Nathan Sobo Date: Tue, 14 Sep 2021 16:28:26 -0600 Subject: [PATCH] Synthesize GitHub avatar URL and follow redirects when fetching it Co-Authored-By: Max Brunsfeld --- server/src/rpc.rs | 2 +- zed/src/http.rs | 4 ++-- zed/src/user.rs | 4 +++- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/server/src/rpc.rs b/server/src/rpc.rs index 14e520d58973f09e9850e4b35dc56f8930a7f91d..d4cc596810d51acf40fd2267112c093c3955d2eb 100644 --- a/server/src/rpc.rs +++ b/server/src/rpc.rs @@ -558,8 +558,8 @@ impl Server { .into_iter() .map(|user| proto::User { id: user.id.to_proto(), + avatar_url: format!("https://github.com/{}.png?size=128", user.github_login), github_login: user.github_login, - avatar_url: String::new(), }) .collect(); self.peer diff --git a/zed/src/http.rs b/zed/src/http.rs index 68f1610c2749c8e374ddd5c8a81beef0281b06f9..30a7a08a519950beee6f28729f2af2f6c9df363a 100644 --- a/zed/src/http.rs +++ b/zed/src/http.rs @@ -2,8 +2,8 @@ pub use anyhow::{anyhow, Result}; use futures::future::BoxFuture; use std::sync::Arc; pub use surf::{ - http::{Method, Request, Response as ServerResponse}, - Response, Url, + http::{Method, Response as ServerResponse}, + Request, Response, Url, }; pub trait HttpClient: Send + Sync { diff --git a/zed/src/user.rs b/zed/src/user.rs index ee9915ac3e6b21215fd98d3fb141e712a01c3907..3a119474e1e7397b5c5352ffb13cddd27f98ae9c 100644 --- a/zed/src/user.rs +++ b/zed/src/user.rs @@ -128,7 +128,9 @@ impl User { async fn fetch_avatar(http: &dyn HttpClient, url: &str) -> Result> { let url = Url::parse(url).with_context(|| format!("failed to parse avatar url {:?}", url))?; - let request = Request::new(Method::Get, url); + let mut request = Request::new(Method::Get, url); + request.middleware(surf::middleware::Redirect::default()); + let mut response = http .send(request) .await