test: firefox detectportal returns HTTP/1.1

This commit is contained in:
zonyitoo
2026-07-05 01:49:31 +08:00
parent 3e0120b8b3
commit 08b6cd9bb8
3 changed files with 26 additions and 9 deletions
+9 -3
View File
@@ -5,6 +5,7 @@ use std::{
str,
};
use byte_string::ByteStr;
use tokio::{
io::{AsyncBufReadExt, AsyncWriteExt, BufReader},
time::{self, Duration},
@@ -86,7 +87,8 @@ async fn socks4_relay_connect() {
let svr = Socks4TestServer::new(SERVER_ADDR, LOCAL_ADDR, PASSWORD, METHOD);
svr.run().await;
const HTTP_REQUEST: &[u8] = b"GET /success.txt HTTP/1.0\r\nHost: detectportal.firefox.com\r\nAccept: */*\r\n\r\n";
const HTTP_REQUEST: &[u8] =
b"GET /success.txt HTTP/1.1\r\nHost: detectportal.firefox.com\r\nAccept: */*\r\nConnection: close\r\n\r\n";
let mut c = Socks4TcpClient::connect(("detectportal.firefox.com", 80), LOCAL_ADDR, Vec::new())
.await
@@ -100,6 +102,10 @@ async fn socks4_relay_connect() {
let mut buf = Vec::new();
r.read_until(b'\n', &mut buf).await.unwrap();
let http_status = b"HTTP/1.0 200 OK\r\n";
assert!(buf.starts_with(http_status));
let http_status = b"HTTP/1.1 200 OK\r\n";
assert!(
buf.starts_with(http_status),
"HTTP status line mismatched, got: {:?}",
ByteStr::new(&buf)
);
}
+9 -3
View File
@@ -5,6 +5,7 @@ use std::{
str,
};
use byte_string::ByteStr;
use tokio::{
io::{AsyncBufReadExt, AsyncWriteExt, BufReader},
time::{self, Duration},
@@ -132,7 +133,8 @@ async fn socks5_relay_aead() {
.await
.unwrap();
let req = b"GET /success.txt HTTP/1.0\r\nHost: detectportal.firefox.com\r\nAccept: */*\r\n\r\n";
let req =
b"GET /success.txt HTTP/1.1\r\nHost: detectportal.firefox.com\r\nAccept: */*\r\nConnection: close\r\n\r\n";
c.write_all(req).await.unwrap();
c.flush().await.unwrap();
@@ -141,6 +143,10 @@ async fn socks5_relay_aead() {
let mut buf = Vec::new();
r.read_until(b'\n', &mut buf).await.unwrap();
let http_status = b"HTTP/1.0 200 OK\r\n";
assert!(buf.starts_with(http_status));
let http_status = b"HTTP/1.1 200 OK\r\n";
assert!(
buf.starts_with(http_status),
"HTTP status line mismatched, got: {:?}",
ByteStr::new(&buf)
);
}
+8 -3
View File
@@ -72,7 +72,8 @@ async fn tcp_tunnel() {
// Connect it directly, because it is now established a TCP tunnel with detectportal.firefox.com
let mut stream = TcpStream::connect(("127.0.0.1", local_port)).await.unwrap();
let req = b"GET /success.txt HTTP/1.0\r\nHost: detectportal.firefox.com\r\nAccept: */*\r\n\r\n";
let req =
b"GET /success.txt HTTP/1.1\r\nHost: detectportal.firefox.com\r\nAccept: */*\r\nConnection: close\r\n\r\n";
stream.write_all(req).await.unwrap();
stream.flush().await.unwrap();
@@ -81,8 +82,12 @@ async fn tcp_tunnel() {
let mut buf = Vec::new();
r.read_until(b'\n', &mut buf).await.unwrap();
let http_status = b"HTTP/1.0 200 OK\r\n";
assert!(buf.starts_with(http_status));
let http_status = b"HTTP/1.1 200 OK\r\n";
assert!(
buf.starts_with(http_status),
"HTTP status line mismatched, got: {:?}",
ByteStr::new(&buf)
);
}
#[tokio::test]