1.6 KiB
1.6 KiB
从0到1实现一个web服务器
实现https访问
- 生成证书
- 方式1:使用openssl生成证书
openssl pkcs12 -export -in fullchain.pem -inkey privkey.pem -out keystore.p12 -name myhttps -CAfile chain.pem -caname root
- 方式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)
- 代码参照: top.yexuejc.demo.core.WebServer.startHttps
扩展一个ctrl能正常处理请求
- 定义@RestController和@GetMapping注解
- 定义扫描器和模拟bean容器: ControllerSupplier
- 接入处理逻辑: RequestHandler line 49
Response response = ControllerSupplier.invoke(request);
- 程序入口装配: WebServerApplication line 16
ControllerSupplier.builder(WebServerApplication.class);
启动参数配置
参照 WebServerApplication.argsProcess
配置文件读取
参照 AppConfig