在swagger中添加代理授权标头

时间:2017-11-27 10:56:13

标签: asp.net-core swagger-ui swashbuckle

我需要使用.net核心在swagger ui上添加特定标头。有没有办法像这样包含标题?

已经尝试过:

  • 实施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"
    });
    

两者都没有用。当我更改标题名称时,一切正常,但是这个特定的标题会从通话中消失。

你有没有遇到过这个问题?怎么解决这个问题?

1 个答案:

答案 0 :(得分:2)

来自:https://developer.mozilla.org/en-US/docs/Glossary/Forbidden_header_name

禁止标头名称是无法以编程方式修改的HTTP标头名称;特别是,HTTP请求标头名称。

...

禁止标题名称以Proxy-或Sec-开头,或由以下其中一个组成:

  • 接收字符集
  • 接受编码
  • 访问控制请求报头
  • 访问控制请求-方法
  • 连接
  • 的Content-Length
  • 曲奇
  • COOKIE2
  • 日期
  • DNT
  • 期望
  • 主机
  • 保持活动
  • 来源
  • 代理 -
  • 秒 -
  • Referer的
  • TE
  • 拖车
  • 传送编码
  • 升级
相关问题