@@ -1097,16 +1097,12 @@ async fn get_online_config_servers(
10971097 online_config_url : & str ,
10981098) -> Result < Vec < ServerInstanceConfig > , Box < dyn std:: error:: Error > > {
10991099 use log:: warn;
1100+ use mime:: Mime ;
11001101 use reqwest:: { redirect:: Policy , Client } ;
11011102
11021103 #[ inline]
11031104 async fn get_online_config ( online_config_url : & str ) -> reqwest:: Result < String > {
1104- static SHADOWSOCKS_USER_AGENT : & str = concat ! (
1105- env!( "CARGO_PKG_NAME" ) ,
1106- "/" ,
1107- env!( "CARGO_PKG_VERSION" ) ,
1108- ) ;
1109-
1105+ static SHADOWSOCKS_USER_AGENT : & str = concat ! ( env!( "CARGO_PKG_NAME" ) , "/" , env!( "CARGO_PKG_VERSION" ) ) ;
11101106
11111107 let client = Client :: builder ( )
11121108 . user_agent ( SHADOWSOCKS_USER_AGENT )
@@ -1131,14 +1127,29 @@ async fn get_online_config_servers(
11311127 // Content-Type: application/json; charset=utf-8
11321128 // mandatory in standard SIP008
11331129 match response. headers ( ) . get ( "Content-Type" ) {
1134- Some ( h) => {
1135- if h != "application/json; charset=utf-8" {
1136- warn ! (
1137- "SIP008 Content-Type must be \" application/json; charset=utf-8\" , but found {}" ,
1138- h. to_str( ) . unwrap_or( "[non-utf8-value]" )
1139- ) ;
1130+ Some ( h) => match h. to_str ( ) {
1131+ Ok ( hstr) => match hstr. parse :: < Mime > ( ) {
1132+ Ok ( content_type) => {
1133+ if content_type. type_ ( ) == mime:: APPLICATION
1134+ && content_type. subtype ( ) == mime:: JSON
1135+ && content_type. get_param ( "charset" ) == Some ( mime:: UTF_8 )
1136+ {
1137+ trace ! ( "checked Content-Type: {:?}" , h) ;
1138+ } else {
1139+ warn ! (
1140+ "Content-Type is not \" application/json; charset=utf-8\" , which is mandatory in standard SIP008. found {:?}" ,
1141+ h
1142+ ) ;
1143+ }
1144+ }
1145+ Err ( err) => {
1146+ warn ! ( "Content-Type parse failed, value: {:?}, error: {}" , h, err) ;
1147+ }
1148+ } ,
1149+ Err ( ..) => {
1150+ warn ! ( "Content-Type is not a UTF-8 string: {:?}" , h) ;
11401151 }
1141- }
1152+ } ,
11421153 None => {
11431154 warn ! ( "missing Content-Type in SIP008 response from {}" , online_config_url) ;
11441155 }
0 commit comments