简体   繁体   English

如何在linux中用c编写http1.0代理服务器?

[英]How to write a http1.0 proxy server in c in linux?

I must develop proxy server that work with only HTTP 1.0 in Linux and by c . 我必须开发在Linux和c中只使用HTTP 1.0的代理服务器。 I need some hint to start developing . 我需要一些提示才能开始开发。

  • I assume you are confident in using linux and the language c (no hints for that, else don't start with developing a proxy) 我假设您对使用Linux和语言c有信心(没有提示,否则不要从开发代理开始)
  • Read and understand the RFC 1945 HTTP/1.0 (pay attention to the specific mentioning of proxy) 阅读并理解RFC 1945 HTTP / 1.0 (注意具体提到的代理)
  • Determine what kind of proxy you want (web/caching/content-filter/anonymizer/transparent/non-transparent/reverse/gateway/tunnel/...) 确定您想要的代理类型(web / caching / content-filter / anonymizer / transparent / non-transparent / reverse / gateway / tunnel / ...)
  • Start developing the server 开始开发服务器

Basic steps 基本步骤

  1. Open port 打开端口
  2. Listen on port 听口岸
  3. Get all request sent from the client to that port (maybe make the whole thing multithreaded to be able to handle more than 1 request at a time) 获取从客户端发送到该端口的所有请求(可能使整个事物多线程,以便能够一次处理多个请求)
  4. Determine if it is a valid HTTP 1.0 request 确定它是否是有效的HTTP 1.0请求
  5. Extract the request components 提取请求组件
  6. Rebuild the request according to what type of proxy you are 根据您的代理类型重建请求
  7. Send the new request 发送新请求
  8. Get the response 得到回应
  9. Send response to client 向客户发送回复

How to create a proxy server: 如何创建代理服务器:

  1. Open a port to listen on 打开一个端口来收听
  2. Catch all incoming requests on that report 捕获该报告上的所有传入请求
  3. Determine the web address requested 确定所请求的Web地址
  4. Open a connection to the host and forward the request 打开与主机的连接并转发请求
  5. Receive response 收到回复
  6. Send the response back to the requesting client 将响应发送回请求客户端

Additionally: Use threads to allow for multiple requests to the server. 另外:使用线程允许对服务器的多个请求。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM