libservo: Add a delegate method for HTTP authentication (#35400)

Add a delegate method for HTTP authentication and a related
`AuthenticationRequest` object that carries with it the URL as well as
whether or not the authentication request is for a proxy or not.

This is now separate from the prompt API because requesting
authentication doesn't necessarily involve prompting -- this is an
implementation detail of the embedder. In addition, the internal bits
are cleaned up slightly.

Signed-off-by: Martin Robinson <mrobinson@igalia.com>
This commit is contained in:
Martin Robinson 2025-02-11 00:39:24 +01:00 committed by GitHub
parent 118a813dba
commit 8486e585f5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
9 changed files with 149 additions and 103 deletions

View file

@ -17,6 +17,7 @@ use devtools_traits::{
ChromeToDevtoolsControlMsg, DevtoolsControlMsg, HttpRequest as DevtoolsHttpRequest,
HttpResponse as DevtoolsHttpResponse, NetworkEvent,
};
use embedder_traits::AuthenticationResponse;
use flate2::write::{GzEncoder, ZlibEncoder};
use flate2::Compression;
use headers::authorization::Basic;
@ -1577,8 +1578,10 @@ fn test_user_credentials_prompt_when_proxy_authentication_is_required() {
let (embedder_proxy, embedder_receiver) = create_embedder_proxy_and_receiver();
let _ = receive_credential_prompt_msgs(
embedder_receiver,
Some("username".to_string()),
Some("test".to_string()),
Some(AuthenticationResponse {
username: "username".into(),
password: "test".into(),
}),
);
let mut context = new_fetch_context(None, Some(embedder_proxy), None);
@ -1625,8 +1628,10 @@ fn test_prompt_credentials_when_client_receives_unauthorized_response() {
let (embedder_proxy, embedder_receiver) = create_embedder_proxy_and_receiver();
let _ = receive_credential_prompt_msgs(
embedder_receiver,
Some("username".to_string()),
Some("test".to_string()),
Some(AuthenticationResponse {
username: "username".into(),
password: "test".into(),
}),
);
let mut context = new_fetch_context(None, Some(embedder_proxy), None);
@ -1670,7 +1675,7 @@ fn test_prompt_credentials_user_cancels_dialog_input() {
.build();
let (embedder_proxy, embedder_receiver) = create_embedder_proxy_and_receiver();
let _ = receive_credential_prompt_msgs(embedder_receiver, None, None);
let _ = receive_credential_prompt_msgs(embedder_receiver, None);
let mut context = new_fetch_context(None, Some(embedder_proxy), None);
let response = fetch_with_context(request, &mut context);
@ -1715,8 +1720,10 @@ fn test_prompt_credentials_user_input_incorrect_credentials() {
let (embedder_proxy, embedder_receiver) = create_embedder_proxy_and_receiver();
let _ = receive_credential_prompt_msgs(
embedder_receiver,
Some("test".to_string()),
Some("test".to_string()),
Some(AuthenticationResponse {
username: "test".into(),
password: "test".into(),
}),
);
let mut context = new_fetch_context(None, Some(embedder_proxy), None);

View file

@ -28,7 +28,7 @@ use std::sync::{Arc, LazyLock, Mutex, RwLock, Weak};
use crossbeam_channel::{unbounded, Receiver, Sender};
use devtools_traits::DevtoolsControlMsg;
use embedder_traits::{EmbedderMsg, EmbedderProxy, EventLoopWaker};
use embedder_traits::{AuthenticationResponse, EmbedderMsg, EmbedderProxy, EventLoopWaker};
use futures::future::ready;
use http_body_util::combinators::BoxBody;
use http_body_util::{BodyExt, Empty, Full};
@ -125,21 +125,13 @@ fn create_embedder_proxy_and_receiver() -> (EmbedderProxy, Receiver<EmbedderMsg>
fn receive_credential_prompt_msgs(
embedder_receiver: Receiver<EmbedderMsg>,
username: Option<String>,
password: Option<String>,
response: Option<AuthenticationResponse>,
) -> std::thread::JoinHandle<()> {
std::thread::spawn(move || loop {
let embedder_msg = embedder_receiver.recv().unwrap();
match embedder_msg {
embedder_traits::EmbedderMsg::Prompt(_, prompt_definition, _prompt_origin) => {
match prompt_definition {
embedder_traits::PromptDefinition::Credentials(ipc_sender) => {
ipc_sender
.send(embedder_traits::PromptCredentialsInput { username, password })
.unwrap();
},
_ => unreachable!(),
}
embedder_traits::EmbedderMsg::RequestAuthentication(_, _, _, response_sender) => {
let _ = response_sender.send(response);
break;
},
embedder_traits::EmbedderMsg::WebResourceRequested(..) => {},