songquanpeng / message-pusher

搭建专属于你的消息推送服务,支持多种消息推送方式,支持 Markdown,基于 Golang 仅单可执行文件,开箱即用
https://msgpusher.com
MIT License
2.58k stars 385 forks source link

API 里的 post json 模式下 Content-Type: application/json 校验能否采用包含匹配而非完全匹配?部分软件发送 http 请求时会自动附带 Content-Type: application/json; charset=utf-8 #130

Open zj1123581321 opened 7 months ago

zj1123581321 commented 7 months ago

例行检查

问题描述 我使用 Postman 调用项目 API 发送 Post Json 请求,一切正常。 我使用 Quicker软件 您的指尖工具箱 - Quicker 的 http 模块发送则会报错,抓包发现是因为它的 Header 为:

Content-Type: application/json; charset=utf-8

image

而项目 API 校验采用完全匹配形式,所以就会报错。 复现步骤 以上述 header 在 postman 中模拟测试即可复现。

预期结果 能否将 API 的校验方式修改为【包含】?让项目更健壮?

zjy4fun commented 3 months ago

https://github.com/songquanpeng/message-pusher/blob/ce8dd677e97108d0fd096e6bfffa3309725015b1/controller/message.go#L49

改为

contentType := c.Request.Header.Get("Content-Type")
mimeType := strings.Split(contentType, ";")[0]
if mimeType == "application/json" {
//...
}