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

Explicitly pass non-json upstream response body backend_responses.<label>.body #182

Closed
filex opened this issue Apr 6, 2021 · 4 comments · Fixed by #212
Closed

Explicitly pass non-json upstream response body backend_responses.<label>.body #182

filex opened this issue Apr 6, 2021 · 4 comments · Fixed by #212
Labels
enhancement New feature or request

Comments

@filex
Copy link
Contributor

filex commented Apr 6, 2021

When I define an upstream request with a label (other than default), I have to define a response{}, too. Because otherwise Couper wouldn't know what to pass downstream.

It is straight-forward to define response status and headers. But currently I cannot simply copy the response body:

server "pass" {
  endpoint "/teapot" {
    request "st" {
      url = "https://httpbin.org/status/418"
    }
    response {
      status = backend_responses.st.status
      headers = backend_responses.st.headers
      body = backend_responses.st.body
    }
  }
}

… because backend_responses.<label>.body doesn't exist :)

We should provide the de-chunked, de-compressed bytes of the response body in that property. E.g. to allow for useless string expressions like

 "Body was: ${backend_responses.st.body}"

The string must also be binary-safe to pass arbitrary content, e.g. pass a PDF generated by an upstream service. (And a binary-string containing a null byte shouldn't truncate the value :))

At first, it's not about optimizing this kind of operation. We can buffer the download, pull the bytes it through the expression evaluation and then compress them on the way to the client.

@filex filex added the enhancement New feature or request label Apr 6, 2021
@johakoch johakoch linked a pull request Apr 16, 2021 that will close this issue
@johakoch
Copy link
Collaborator

What about request.body? New issue?

@filex
Copy link
Contributor Author

filex commented Apr 16, 2021

What about request.body?

Good idea. We can cover this here, too.

Can you provide a request configuration that would (more or less) mimic a proxy?

@johakoch
Copy link
Collaborator

Also, backend_requests.<label> has no .json_body and no .body (only .form_body)

@johakoch
Copy link
Collaborator

@filex

Can you provide a request configuration that would (more or less) mimic a proxy?

Something like

request {
  method = request.method
  url = "https://some.other.host/path/to${request.path}"
  headers = request.headers
  body = request.body
}

?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants