C#中的HTTP代理服务器

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/710379/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-04 14:20:03  来源:igfitidea点击:

HTTP Proxy server in C#

c#proxyhttplistener

提问by cfeduke

My company is experimenting with writing a proxy server using the .NET Fx 3.5 and C#. From our researchI have read that HttpListener is not a good candidate for a proxy server though I am unsure as to why.

我的公司正在试验使用 .NET Fx 3.5 和 C# 编写代理服务器。从我们的研究中,我了解到 HttpListener 不是代理服务器的良好候选者,尽管我不确定为什么。

We are currently working with the Mentalis proxy example source codethough that will involve, among other things, implementing our own logging and performance counters. Using HttpListener will wrap Http.sys which will give us some of the performance statistics we require out of the box.

我们目前正在使用Mentalis 代理示例源代码,但除其他外,这将涉及实现我们自己的日志记录和性能计数器。使用 HttpListener 将包装 Http.sys,这将为我们提供一些开箱即用的性能统计信息。

So why is HttpListener a bad candidate for HTTP proxy work?

那么为什么 HttpListener 不适合 HTTP 代理工作呢?

(And yes we are considering Squid 3.1 by writing or configuring an ICAP server as well.)

(是的,我们也在通过编写或配置 ICAP 服务器来考虑使用 Squid 3.1。)

采纳答案by Richard

HttpListener is in .NET to provide a major building block for a simpleHTTP server. Where simple includes not supporting high operation rates.

HttpListener 在 .NET 中为简单的HTTP 服务器提供主要构建块。简单包括不支持高操作率。

Typically HTTP proxies need to be very low overhead to support many concurrent connections as well as providing the proxy's function (which depends on the type of proxy).

通常 HTTP 代理需要非常低的开销来支持许多并发连接以及提供代理的功能(这取决于代理的类型)。

Proxies are detailed in RFC 2616 §8.1.3) and that immediately provides one item that (if I understand HttpListener correctly) is not possible:

代理在RFC 2616 §8.1.3 中进行了详细说明,并且立即提供了一项(如果我正确理解 HttpListener)是不可能的:

The proxy server MUST signal persistent connections separately with its clients and the origin servers (or other proxy servers) that it connects to. Each persistent connection applies to only one transport link.

代理服务器必须与它的客户端和它所连接的源服务器(或其他代理服务器)分别发出持久连接信号。每个持久连接仅适用于一个传输链路。

回答by Richard

You might also consider that the windows port of nginx was released a few days ago. Many sites that have squid and varnish experience are very pleased after converting to nginx. Then there is always whatever MS is calling ISA server these days.

你可能还会认为nginx的windows端口是前几天发布的。很多有squid和varnish经验的网站在转换成nginx后都非常满意。那么这些天总是有任何 MS 调用 ISA 服务器。

Gone off to look at the Mentalis code now :D

现在去看看 Mentalis 代码:D