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

gateway: support extension hooks #457

Open
willscott opened this issue Aug 29, 2023 · 1 comment
Open

gateway: support extension hooks #457

willscott opened this issue Aug 29, 2023 · 1 comment
Labels
need/triage Needs initial labeling and prioritization

Comments

@willscott
Copy link
Contributor

Per ipfs/specs#431 - there is a desire for clients to be able to signal support for additional semantics in their requests to the gateway handler.
ipfs/specs#412 introduced a spec location for signalling of additional parameters.

The ask of the boxo library is how to support usage of the gateway handler with registered support for additional semantics / callback hooks to allow for transformation / changed behavior based upon signalled requests for such.

Currently, the best approach would seem to be for the server to wrap the boxo handler with middleware, which would have to re-parse inbound requests to identify extension semantics, and filter/transform the response as a byte stream. That approach seems like it may lead to unwanted amounts of code reuse. On the flip side, the choice of appropriate hooks to allow server code to plug into does not seem immediately obvious either.

@willscott willscott added the need/triage Needs initial labeling and prioritization label Aug 29, 2023
@Jorropo
Copy link
Contributor

Jorropo commented Aug 29, 2023

favor composition over inheritance

  • Someone once said.

And thus wrap the handler.
We could decouple the car serialization from the rest of the gateway implementation.
So I would do something along the lines of:

// Pseudo code

// BlockStreamResponseWriter is a copy of [http.ResponseWriter] except write takes in a blocks argument instead of bytes.
// This allows consumers to modify the car without having to reparse it.
type BlockStreamResponseWriter interface{
	Header() http.Header
	Write(blocks.Block) error
	WriteHeader(statusCode int, carRoots []cid.Cid) // I'm unsure about carRoots
}

// ServeCar only supports the responses formats which outputs cars and should only be used for code that wants to do specific things with the car.
func (*Gateway) ServeCar(w BlockStreamResponseWriter, req *http.Request) error

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
need/triage Needs initial labeling and prioritization
Projects
None yet
Development

No branches or pull requests

2 participants