大摇大摆地添加Proxy-Authorizationheader
Add Proxy-Authorization header in swagger
我需要使用 .net 核心在 swagger ui 上添加特定的 header。有没有办法像这样包含 header?
已经尝试过:
正在实施 IOperationFilter:
public void Apply(Operation operation, OperationFilterContext context)
{
if (operation.Parameters == null)
operation.Parameters = new List<IParameter>();
if (operation.Parameters.All(p => p.Name != "Proxy-Authorization"))
{
operation.Parameters.Add(new NonBodyParameter
{
Name = "Proxy-Authorization",
In = "header",
Description = "Proxy-Authorization token",
Required = true,
Type = "string"
});
}
}
添加安全定义:
options.AddSecurityDefinition("Proxy-Authorization", new ApiKeyScheme()
{
In = "header",
Description = "Please insert Proxy Authorization Secret into field",
Name = "Proxy-Authorization",
Type = "apiKey"
});
两者均无效。当我更改 header 名称时,一切正常,但这个特定的 header 已从调用中删除。
你遇到过这个问题吗?如何解决?
发件人:https://developer.mozilla.org/en-US/docs/Glossary/Forbidden_header_name
禁止的 header 名称是一个 HTTP header 名称,不能以编程方式修改;具体来说,一个 HTTP 请求 header name.
...
禁止 header 名称以 Proxy- 或 Sec- 开头,或由以下之一组成:
- Accept-Charset
- Accept-Encoding
- Access-Control-Request-Headers
- Access-Control-Request-Method
- 连接
- Content-Length
- Cookie
- Cookie2
- 日期
- DNT
- 期待
- 主持人
- Keep-Alive
- 来源
- 代理-
- 秒-
- 推荐人
- TE
- 预告片
- Transfer-Encoding
- 升级
- 通过
我需要使用 .net 核心在 swagger ui 上添加特定的 header。有没有办法像这样包含 header?
已经尝试过:
正在实施 IOperationFilter:
public void Apply(Operation operation, OperationFilterContext context) { if (operation.Parameters == null) operation.Parameters = new List<IParameter>(); if (operation.Parameters.All(p => p.Name != "Proxy-Authorization")) { operation.Parameters.Add(new NonBodyParameter { Name = "Proxy-Authorization", In = "header", Description = "Proxy-Authorization token", Required = true, Type = "string" }); } }
添加安全定义:
options.AddSecurityDefinition("Proxy-Authorization", new ApiKeyScheme() { In = "header", Description = "Please insert Proxy Authorization Secret into field", Name = "Proxy-Authorization", Type = "apiKey" });
两者均无效。当我更改 header 名称时,一切正常,但这个特定的 header 已从调用中删除。
你遇到过这个问题吗?如何解决?
发件人:https://developer.mozilla.org/en-US/docs/Glossary/Forbidden_header_name
禁止的 header 名称是一个 HTTP header 名称,不能以编程方式修改;具体来说,一个 HTTP 请求 header name.
...
禁止 header 名称以 Proxy- 或 Sec- 开头,或由以下之一组成:
- Accept-Charset
- Accept-Encoding
- Access-Control-Request-Headers
- Access-Control-Request-Method
- 连接
- Content-Length
- Cookie
- Cookie2
- 日期
- DNT
- 期待
- 主持人
- Keep-Alive
- 来源
- 代理-
- 秒-
- 推荐人
- TE
- 预告片
- Transfer-Encoding
- 升级
- 通过