## Titanium Web Proxy
A lightweight HTTP(S) proxy server written in C#.
[![.NET Core](https://github.com/justcoding121/titanium-web-proxy/actions/workflows/dotnetcore.yml/badge.svg?branch=develop)](https://github.com/justcoding121/titanium-web-proxy/actions/workflows/dotnetcore.yml) [![Join the chat at https://gitter.im/Titanium-Web-Proxy/Lobby](https://badges.gitter.im/Titanium-Web-Proxy/Lobby.svg)](https://gitter.im/Titanium-Web-Proxy/Lobby?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
Report bugs or raise issues here. For programming help use [StackOverflow](http://stackoverflow.com/questions/tagged/titanium-web-proxy) with the tag Titanium-Web-Proxy.
* [API Documentation](https://justcoding121.github.io/titanium-web-proxy/docs/api/Titanium.Web.Proxy.ProxyServer.html)
* [Wiki & Contribution guidelines](https://github.com/justcoding121/Titanium-Web-Proxy/wiki)
### Features
* Multithreaded and asynchronous proxy employing server connection pooling, certificate cache, and buffer pooling
* View, modify, redirect and block requests or responses
* Supports mutual SSL authentication, proxy authentication & automatic upstream proxy detection
* Supports kerberos, NTLM authentication over HTTP protocols on windows domain controlled networks
* SOCKS4/5 Proxy support
### Installation
Install by [nuget](https://www.nuget.org/packages/Titanium.Web.Proxy)
For beta releases on [beta branch](https://github.com/justcoding121/Titanium-Web-Proxy/tree/beta)
Install-Package Titanium.Web.Proxy -Pre
For stable releases on [stable branch](https://github.com/justcoding121/Titanium-Web-Proxy/tree/stable)
Install-Package Titanium.Web.Proxy
Supports
* .NET Standard 2.0 or above
* .NET Framework 4.5 or above
### Note to contributors
#### Road map
* Fix [outstanding bugs](https://github.com/justcoding121/Titanium-Web-Proxy/issues?q=is%3Aopen+is%3Aissue+label%3Abug)
* Support reading request and response body as stream [#823](https://github.com/justcoding121/Titanium-Web-Proxy/issues/823)
* Stop throwing new exceptions [#634](https://github.com/justcoding121/Titanium-Web-Proxy/issues/634)
* Support HTTP 2.0
#### Collaborators
The owner of this project, [justcoding121](https://github.com/justcoding121), is considered to be inactive from this project due to his busy work schedule. However, we have a collaborator listed below who time and again shows up to maintain this project. Please create pull requests prioritizing bug fixes for the attention of collaborators.
* [honfika](https://github.com/honfika)
### Development environment
#### Windows
* Visual Studio Code as IDE for .NET
* Visual Studio 2022 as IDE for .NET Framework/.NET
#### Mac OS
* Visual Studio Code as IDE for .NET
* Visual Studio 2022 as IDE for Mono
#### Linux
* Visual Studio Code as IDE for .NET
* Mono develop as IDE for Mono
### Usage
Refer the HTTP Proxy Server library in your project and look up the test project to learn usage.
Setup HTTP proxy:
```csharp
var proxyServer = new ProxyServer();
// locally trust root certificate used by this proxy
proxyServer.CertificateManager.TrustRootCertificate(true);
// optionally set the Certificate Engine
// Under Mono only BouncyCastle will be supported
//proxyServer.CertificateManager.CertificateEngine = Network.CertificateEngine.BouncyCastle;
proxyServer.BeforeRequest += OnRequest;
proxyServer.BeforeResponse += OnResponse;
proxyServer.ServerCertificateValidationCallback += OnCertificateValidation;
proxyServer.ClientCertificateSelectionCallback += OnCertificateSelection;
var explicitEndPoint = new ExplicitProxyEndPoint(IPAddress.Any, 8000, true)
{
// Use self-issued generic certificate on all https requests
// Optimizes performance by not creating a certificate for each https-enabled domain
// Useful when certificate trust is not required by proxy clients
//GenericCertificate = new X509Certificate2(Path.Combine(System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location), "genericcert.pfx"), "password")
};
// Fired when a CONNECT request is received
explicitEndPoint.BeforeTunnelConnectRequest += OnBeforeTunnelConnectRequest;
// An explicit endpoint is where the client knows about the existence of a proxy
// So client sends request in a proxy friendly manner
proxyServer.AddEndPoint(explicitEndPoint);
proxyServer.Start();
// Transparent endpoint is useful for reverse proxy (client is not aware of the existence of proxy)
// A transparent endpoint usually requires a network router port forwarding HTTP(S) packets or DNS
// to send data to this endPoint
var transparentEndPoint = new TransparentProxyEndPoint(IPAddress.Any, 8001, true)
{
// Generic Certificate hostname to use
// when SNI is disabled by client
GenericCertificateName = "google.com"
};
proxyServer.AddEndPoint(transparentEndPoint);
//proxyServer.UpStreamHttpProxy = new ExternalProxy() { HostName = "localhost", Port = 8888 };
//proxyServer.UpStreamHttpsProxy = new ExternalProxy() { HostName = "localhost", Port = 8888 };
foreach (var endPoint in proxyServer.ProxyEndPoints)
Console.WriteLine("Listening on '{0}' endpoint at Ip {1} and port: {2} ",
endPoint.GetType().Name, endPoint.IpAddress, endPoint.Port);
// Only explicit proxies can be set as system proxy!
proxyServer.SetAsSystemHttpProxy(explicitEndPoint);
proxyServer.SetAsSystemHttpsProxy(explicitEndPoint);
// wait here (You can use something else as a wait function, I am using this as a demo)
Console.Read();
// Unsubscribe & Quit
explicitEndPoint.BeforeTunnelConnectRequest -= OnBeforeTunnelConnectRequest;
proxyServer.BeforeRequest -= OnRequest;
proxyServer.BeforeResponse -= OnResponse;
proxyServer.ServerCertificateValidationCallback -= OnCertificateValidation;
proxyServer.ClientCertificateSelectionCallback -= OnCertificateSelection;
proxyServer.Stop();
```
Sample request and response event handlers
```csharp
private async Task OnBeforeTunnelConnectRequest(object sender, TunnelConnectSessionEventArgs e)
{
string hostname = e.HttpClient.Request.RequestUri.Host;
if (hostname.Contains("dropbox.com"))
{
// Exclude Https addresses you don't want to proxy
// Useful for clients that use certificate pinning
// for example dropbox.com
e.DecryptSsl = false;
}
}
public async Task OnRequest(object sender, SessionEventArgs e)
{
Console.WriteLine(e.HttpClient.Request.Url);
// read request headers
var requestHeaders = e.HttpClient.Request.Headers;
var method = e.HttpClient.Request.Method.ToUpper();
if ((method == "POST" || method == "PUT" || method == "PATCH"))
{
// Get/Set request body bytes
byte[] bodyBytes = await e.GetRequestBody();
e.SetRequestBody(bodyBytes);
// Get/Set request body as string
string bodyString = await e.GetRequestBodyAsString();
e.SetRequestBodyString(bodyString);
// store request
// so that you can find it from response handler
e.UserData = e.HttpClient.Request;
}
// To cancel a request with a custom HTML content
// Filter URL
if (e.HttpClient.Request.RequestUri.AbsoluteUri.Contains("google.com"))
{
e.Ok("<!DOCTYPE html>" +
"<html><body><h1>" +
"Website Blocked" +
"</h1>" +
"<p>Blocked by titanium web proxy.</p>" +
"</body>" +
"</html>");
}
// Redirect example
if (e.HttpClient.Request.RequestUri.AbsoluteUri.Contains("wikipedia.org"))
{
e.Redirect("https://www.paypal.com");
}
}
// Modify response
public async Task OnResponse(object sender, SessionEventArgs e)
{
// read response headers
var responseHeaders = e.HttpClient.Response.Headers;
//if (!e.ProxySession.Request.Host.Equals("medeczane.sgk.gov.tr")) return;
if (e.HttpClient.Request.Method == "GET" || e.HttpClient.Request.Method == "POST")
没有合适的资源?快使用搜索试试~ 我知道了~
A cross-platform asynchronous HTTP(S) proxy server in C#..zip
共340个文件
cs:182个
html:98个
json:7个
需积分: 5 0 下载量 113 浏览量
2023-12-27
00:06:55
上传
评论
收藏 1.17MB ZIP 举报
温馨提示
A cross-platform asynchronous HTTP(S) proxy server in C#.
资源推荐
资源详情
资源评论
收起资源包目录
A cross-platform asynchronous HTTP(S) proxy server in C#..zip (340个子文件)
App.config 3KB
app.config 274B
NuGet.config 187B
App.config 169B
App.config 169B
Annotations.cs 44KB
HttpStream.cs 43KB
ProxyServer.cs 34KB
TcpConnectionFactory.cs 33KB
CertificateManager.cs 33KB
Http2Helper.cs 27KB
SslCiphers.cs 24KB
SessionEventArgs.cs 24KB
SslExtension.cs 22KB
Decoder.cs 21KB
ProxySocket.cs 21KB
Socks5Handler.cs 20KB
ProxyTestController.cs 18KB
ExplicitClientHandler.cs 18KB
Encoder.cs 17KB
RequestHandler.cs 17KB
MainWindow.xaml.cs 16KB
WinCertificateMaker.cs 14KB
HttpsHandler.cs 13KB
Socks4Handler.cs 12KB
WinHttpWebProxyFinder.cs 11KB
SslTools.cs 11KB
SystemProxy.cs 10KB
BCCertificateMakerFast.cs 9KB
SocksHandler.cs 9KB
HeaderCollection.cs 9KB
BCCertificateMaker.cs 9KB
HttpHelper.cs 9KB
WinAuthEndPoint.cs 9KB
RequestResponseBase.cs 9KB
Settings.Designer.cs 8KB
Common.cs 8KB
Request.cs 8KB
NestedProxyTests.cs 8KB
TransparentClientHandler.cs 7KB
AuthUserPass.cs 7KB
WinAuthHandler.cs 7KB
SessionEventArgsBase.cs 7KB
StaticTable.cs 7KB
HpackUtil.cs 7KB
SslExtensions.cs 6KB
LittleEndian.cs 6KB
HttpWebClient.cs 6KB
ProxyAuthorizationHandler.cs 6KB
InterceptionTests.cs 5KB
DynamicTable.cs 5KB
HuffmanDecoder.cs 5KB
ProxyInfo.cs 5KB
LimitedStream.cs 5KB
ReverseProxyTests.cs 5KB
ResponseHandler.cs 5KB
RunTime.cs 5KB
TcpHelper.cs 5KB
ClientHelloInfo.cs 5KB
SocksClientHandler.cs 5KB
SessionListItem.cs 5KB
ExpectContinueTests.cs 5KB
NativeMethods.WinHttp.cs 5KB
IAsyncProxyResult.cs 5KB
ProxyService.cs 5KB
Response.cs 4KB
TestServer.cs 4KB
DefaultCertificateDiskCache.cs 4KB
WebSocketDecoder.cs 4KB
AuthMethod.cs 4KB
SystemProxyTest.cs 4KB
HttpHeader.cs 4KB
GenericResponse.cs 4KB
Message.cs 4KB
ServerHelloInfo.cs 4KB
CertificateHandler.cs 4KB
HttpMessageParsing.cs 4KB
TcpServerConnection.cs 3KB
CertificateManagerTests.cs 3KB
ProxyException.cs 3KB
ProxyServerTests.cs 3KB
ExternalProxy.cs 3KB
HttpContinueServer.cs 3KB
HttpsTests.cs 3KB
HuffmanEncoder.cs 3KB
TcpClientConnection.cs 3KB
HeaderBuilder.cs 3KB
Resources.Designer.cs 3KB
TunnelConnectEventArgs.cs 3KB
StreamExtensions.cs 3KB
BeforeSslAuthenticateEventArgs.cs 3KB
RetryPolicy.cs 2KB
AssemblyInfo.cs 2KB
ExplicitProxyEndPoint.cs 2KB
CopyStream.cs 2KB
AuthNone.cs 2KB
HttpContinueClient.cs 2KB
Network.cs 2KB
NativeMethods.Tcp.cs 2KB
KnownHeaders.cs 2KB
共 340 条
- 1
- 2
- 3
- 4
资源评论
Lei宝啊
- 粉丝: 1979
- 资源: 1330
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功