Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

api level error handler must affect endpoint's buffer options #706

Closed
johakoch opened this issue Feb 6, 2023 · 0 comments · Fixed by #710
Closed

api level error handler must affect endpoint's buffer options #706

johakoch opened this issue Feb 6, 2023 · 0 comments · Fixed by #710
Assignees
Labels
bug Something isn't working
Milestone

Comments

@johakoch
Copy link
Collaborator

johakoch commented Feb 6, 2023

Consider the following config:

server {
  api {
    endpoint "/anything" {
      request "r" {
        url = "https://blackhole.webpagetest.org/"
        backend {
          timeout = "1s"
        }
      }

      proxy {
        backend {
          origin = "https://httpbin.org"
        }
      }
    }

    error_handler "backend_timeout" {
      response {
        status = 418
        json_body = {
          resp_json_body_headers = backend_responses.default.json_body.headers
        }
      }
    }
  }
}

The error handler's BufferOpts are BufferResponse (because of the reference to json_body), whereas the endpoint's are BufferNone. So the proxy response's body is not buffered, and resp_json_body_headers is null.

In order to make this config work, api level error handlers must affect api level endpoints' BufferOpts.


Note: Test_StoreInvalidBackendResponse with its configuration testdata/integration/error_handler/06_couper.hcl:

server {
  api {
    endpoint "/anything" {
      proxy {
        backend {
          origin = "${env.COUPER_TEST_BACKEND_ADDR}"

          openapi {
            file = "02_schema.yaml"
          }
        }
      }
    }

    error_handler "backend_openapi_validation" {
      response {
        status = 418
          json_body = {
            req_path = backend_requests.default.path
            resp_status = backend_responses.default.status
            resp_json_body_query = backend_responses.default.json_body.Query
            resp_ct = backend_responses.default.headers.content-type
          }
      }
    }
  }
}

only works because both BufferOpts have BufferResponse set, the endpoint's because of the openapi block, the error handler's because of a reference to json_body.

@johakoch johakoch added the bug Something isn't working label Feb 6, 2023
@johakoch johakoch linked a pull request Feb 9, 2023 that will close this issue
@johakoch johakoch added this to the 1.12.1 milestone Feb 13, 2023
@alex-schneider alex-schneider self-assigned this Feb 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants