这是indexloc提供的服务,不要输入任何密码
Skip to content

Should we have HeaderViolation primitive? #1537

@1xX69

Description

@1xX69

BadRequest may only have field violations and no header violations. Why? Shouldn't we add support for header violations as well?

So the following error:

$ curl -H 'Authorization: Bearer <REDACTED>' https://chat.googleapis.com/v1/spaces
{
  "error": {
    "code": 401,
    "message": "Request had invalid authentication credentials. Expected OAuth 2 access token, login cookie or other valid authentication credential. See https://developers.google.com/identity/sign-in/web/devconsole-project.",
    "status": "UNAUTHENTICATED"
  }
}

could look like this:

{
  "error": {
    "code": 401,
    "message": "Request had invalid authentication credentials. Expected OAuth 2 access token, login cookie or other valid authentication credential. See https://developers.google.com/identity/sign-in/web/devconsole-project.",
    "status": "UNAUTHENTICATED",
    "details": [
      {
        "@type": "type.googleapis.com/google.rpc.BadRequest",
        "headerViolations": [
          {
            "header": "Authorization",
            "description": "Missing or invalid OAuth 2 access token in Authorization header."
          },
          {
            "header": "Cookie",
            "description": "Missing or invalid login cookie."
          }
        ]
      }
    ]
  }
}

here's another usage example:

{
  "error": {
    "code": 400,
    "message": "Failed to parse 'Content-Type' header as UTF-8.",
    "status": "INVALID_ARGUMENT",
    "details": [
      {
        "@type": "type.googleapis.com/google.rpc.BadRequest",
        "headerViolations": [
          {
            "header": "Content-Type",
            "description": "The value of the 'Content-Type' header could not be decoded as UTF-8. Please ensure it is properly encoded."
          }
        ]
      }
    ]
  }
}

Drawbacks:

  1. There's an overhead of N bytes for storing an array of header violations for each response, in Rust it's 24 bytes even when the array is empty.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions