最近在测试proxy_guess的图片302跳转,由于需要标记请求,所以我在请求时同时记录了端口。而有时就发现,haeder中打印的端口居然和后续获取的端口不一致。为此,我做了些测试。并发现了些奇葩的事情。
好吧,这是一个乌龙事件。我发现了这个奇怪现象的前提:
chrome打开了devtool,并保持在【网络】的选项卡
原因是:在加载这种302带跳转的图片时,devtool显示缩略图时会再加载一遍。
测试浏览器为:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/106.0.0.0 Safari/537.36
<?php
if(empty($_GET['token'])){
$_GET['token'] = rand(0,999999);
}
function wlog($text){
$path_file = __DIR__.'/'.'one_request.log';
file_put_contents($path_file,date('Y-m-d H:i:s').' '. (is_array($text)?json_encode($text):$text)."\n", FILE_APPEND);
};
$params = [
'token'=>$_GET['token'],
'p'=>$_SERVER['REMOTE_PORT'],
'protocol'=>$_SERVER['SERVER_PROTOCOL']
];
if(empty($_GET['p'])){
header('port:'.$_SERVER['REMOTE_PORT']);
header('Location: index.php?'.http_build_query($params));
wlog($params);
exit;
}else{
header('port:'.$_SERVER['REMOTE_PORT']);
wlog($params);
header('content-type:image/png');
echo base64_decode('iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAIAAACQd1PeAAAACXBIWXMAAA7EAAAOxAGVKw4bAAAADElEQVQI12NgYGAAAAAEAAEnNCcKAAAAAElFTkSuQmCC');
exit;
}
let image = new Image();
let token = Math.random()
image.onload = function(){
}
image.src = "index.php?token="+token;
# keepalive_timeout 0;//default 75
……
listen 443 ssl ;// http/1.1
# listen 443 ssl http2; //enable H2
……
通过 http2 选项和 keepalive_timeout 可以搭配出4个组合。
| protocol | keepalive_timeout | keep-alive client |
|---|---|---|
| H2 | 75 | y |
| H2 | 0 | x |
| http/1.1 | 75 | y |
| http/1.1 | 0 | x |
2022-10-20 06:35:44 {"token":161829,"p":"15597","protocol":"HTTP\/2.0"}
2022-10-20 06:35:44 {"token":"161829","p":"15597","protocol":"HTTP\/2.0"}
2022-10-20 06:36:28 {"token":"0.5107532597240456","p":"15597","protocol":"HTTP\/2.0"}
2022-10-20 06:36:28 {"token":"0.5107532597240456","p":"15597","protocol":"HTTP\/2.0"}
2022-10-20 06:36:28 {"token":"0.5107532597240456","p":"15635","protocol":"HTTP\/2.0"}
2022-10-20 06:36:28 {"token":"0.5107532597240456","p":"15635","protocol":"HTTP\/2.0"}
2022-10-20 06:40:09 {"token":495172,"p":"15776","protocol":"HTTP\/2.0"}
2022-10-20 06:40:09 {"token":"495172","p":"15777","protocol":"HTTP\/2.0"}
2022-10-20 06:40:49 {"token":"0.8067361045275498","p":"15833","protocol":"HTTP\/2.0"}
2022-10-20 06:40:49 {"token":"0.8067361045275498","p":"15835","protocol":"HTTP\/2.0"}
2022-10-20 06:40:49 {"token":"0.8067361045275498","p":"15834","protocol":"HTTP\/2.0"}
2022-10-20 06:40:49 {"token":"0.8067361045275498","p":"15836","protocol":"HTTP\/2.0"}
2022-10-20 06:32:57 {"token":229425,"p":"15473","protocol":"HTTP\/1.1"}
2022-10-20 06:32:58 {"token":"229425","p":"15473","protocol":"HTTP\/1.1"}
2022-10-20 06:23:50 {"token":"0.6276816635368629","p":"14825","protocol":"HTTP\/1.1"}
2022-10-20 06:23:50 {"token":"0.6276816635368629","p":"14825","protocol":"HTTP\/1.1"}
2022-10-20 06:23:50 {"token":"0.6276816635368629","p":"14826","protocol":"HTTP\/1.1"}
2022-10-20 06:23:50 {"token":"0.6276816635368629","p":"14826","protocol":"HTTP\/1.1"}
2022-10-20 06:31:21 {"token":293483,"p":"15387","protocol":"HTTP\/1.1"}
2022-10-20 06:31:21 {"token":"293483","p":"15388","protocol":"HTTP\/1.1"}
2022-10-20 06:29:48 {"token":"0.5968497764216198","p":"15284","protocol":"HTTP\/1.1"}
2022-10-20 06:29:48 {"token":"0.5968497764216198","p":"15285","protocol":"HTTP\/1.1"}
2022-10-20 06:29:48 {"token":"0.5968497764216198","p":"15286","protocol":"HTTP\/1.1"}
2022-10-20 06:29:48 {"token":"0.5968497764216198","p":"15287","protocol":"HTTP\/1.1"}
一个302跳转图片+关闭会话保持,我猜应该不会有人这么干吧。