mirror of
https://github.com/shadowsocks/shadowsocks-rust.git
synced 2026-11-06 08:14:07 +00:00
test: firefox detectportal returns HTTP/1.1
This commit is contained in:
+9
-3
@@ -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
@@ -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
@@ -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]
|
||||
|
||||
Reference in New Issue
Block a user