2025-07-11 15:36:02 +08:00
..
2025-07-11 15:36:02 +08:00
2025-07-11 15:36:02 +08:00
2025-07-11 15:36:02 +08:00

从0到1实现一个web服务器

实现https访问

  1. 生成证书
    1. 方式1使用openssl生成证书
     openssl pkcs12 -export -in fullchain.pem -inkey privkey.pem -out keystore.p12 -name myhttps -CAfile chain.pem -caname root
    
    1. 方式2使用第三方工具证书key和crt
    # key 和 crt 转换成 PKCS12.p12
    openssl pkcs12 -export -in ssl.crt -inkey ssl.key -out keystore_3rd.p12 -name myhttps -CAfile ca.crt -caname root
    Enter Export Password: (123456)
    Verifying - Enter Export Password: (123456)
    
  2. 代码参照: top.yexuejc.demo.core.WebServer.startHttps

扩展一个ctrl能正常处理请求

  1. 定义@RestController@GetMapping注解
  2. 定义扫描器和模拟bean容器: ControllerSupplier
  3. 接入处理逻辑: RequestHandler line 49
Response response = ControllerSupplier.invoke(request);
  1. 程序入口装配: WebServerApplication line 16
ControllerSupplier.builder(WebServerApplication.class);

启动参数配置

参照 WebServerApplication.argsProcess

配置文件读取

参照 AppConfig