Skip to content
This repository has been archived by the owner on Jul 19, 2022. It is now read-only.

Commit

Permalink
Bug fix: Timeout wasn't being set for HTTP proxies
Browse files Browse the repository at this point in the history
  • Loading branch information
Laiteux committed Nov 16, 2020
1 parent 0d8e522 commit e7e740e
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 32 deletions.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2019-2020 Matt
Copyright (c) 2019-2021 Matt

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
63 changes: 32 additions & 31 deletions src/Milky/Models/Proxy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,10 @@ internal HttpClient GetHttpClient()
{
var httpMessageHandler = GetHttpMessageHandler();

var httpClient = new HttpClient(httpMessageHandler);
var httpClient = new HttpClient(httpMessageHandler)
{
Timeout = Settings.Timeout
};

if (Settings.Backconnect)
{
Expand All @@ -72,40 +75,38 @@ private HttpMessageHandler GetHttpMessageHandler()
CookieContainer = Settings.CookieContainer ?? new CookieContainer()
};
}
else

var timeoutMilliseconds = (int)Settings.Timeout.TotalMilliseconds;

var proxySettings = new SocksSharp.Proxy.ProxySettings()
{
var timeoutMilliseconds = (int)Settings.Timeout.TotalMilliseconds;
Host = Host, Port = Port,
Credentials = Credentials,
ConnectTimeout = timeoutMilliseconds,
ReadWriteTimeOut = timeoutMilliseconds
};

var proxySettings = new SocksSharp.Proxy.ProxySettings()
return Settings.Protocol switch
{
ProxyProtocol.SOCKS4 => new ProxyClientHandler<Socks4>(proxySettings)
{
Host = Host, Port = Port,
Credentials = Credentials,
ConnectTimeout = timeoutMilliseconds,
ReadWriteTimeOut = timeoutMilliseconds
};

return Settings.Protocol switch
AllowAutoRedirect = Settings.AllowAutoRedirect,
UseCookies = Settings.UseCookies,
CookieContainer = Settings.CookieContainer
},
ProxyProtocol.SOCKS4a => new ProxyClientHandler<Socks4a>(proxySettings)
{
ProxyProtocol.SOCKS4 => new ProxyClientHandler<Socks4>(proxySettings)
{
AllowAutoRedirect = Settings.AllowAutoRedirect,
UseCookies = Settings.UseCookies,
CookieContainer = Settings.CookieContainer
},
ProxyProtocol.SOCKS4a => new ProxyClientHandler<Socks4a>(proxySettings)
{
AllowAutoRedirect = Settings.AllowAutoRedirect,
UseCookies = Settings.UseCookies,
CookieContainer = Settings.CookieContainer
},
ProxyProtocol.SOCKS5 => new ProxyClientHandler<Socks5>(proxySettings)
{
AllowAutoRedirect = Settings.AllowAutoRedirect,
UseCookies = Settings.UseCookies,
CookieContainer = Settings.CookieContainer
}
};
}
AllowAutoRedirect = Settings.AllowAutoRedirect,
UseCookies = Settings.UseCookies,
CookieContainer = Settings.CookieContainer
},
ProxyProtocol.SOCKS5 => new ProxyClientHandler<Socks5>(proxySettings)
{
AllowAutoRedirect = Settings.AllowAutoRedirect,
UseCookies = Settings.UseCookies,
CookieContainer = Settings.CookieContainer
}
};
}
}
}

0 comments on commit e7e740e

Please sign in to comment.