@@ -28,24 +28,21 @@ import (
2828
2929func GatewayOption (paths ... string ) ServeOption {
3030 return func (n * core.IpfsNode , _ net.Listener , mux * http.ServeMux ) (* http.ServeMux , error ) {
31- gwConfig , err := getGatewayConfig (n )
31+ config , err := getGatewayConfig (n )
3232 if err != nil {
3333 return nil , err
3434 }
3535
36- gwAPI , err := newGatewayBackend (n )
36+ backend , err := newGatewayBackend (n )
3737 if err != nil {
3838 return nil , err
3939 }
4040
41- gw := gateway .NewHandler (gwConfig , gwAPI )
42- gw = otelhttp .NewHandler (gw , "Gateway" )
43-
44- // By default, our HTTP handler is the gateway handler.
45- handler := gw .ServeHTTP
41+ handler := gateway .NewHandler (config , backend )
42+ handler = otelhttp .NewHandler (handler , "Gateway" )
4643
4744 for _ , p := range paths {
48- mux .HandleFunc (p + "/" , handler )
45+ mux .HandleFunc (p + "/" , handler . ServeHTTP )
4946 }
5047
5148 return mux , nil
@@ -54,18 +51,18 @@ func GatewayOption(paths ...string) ServeOption {
5451
5552func HostnameOption () ServeOption {
5653 return func (n * core.IpfsNode , _ net.Listener , mux * http.ServeMux ) (* http.ServeMux , error ) {
57- gwConfig , err := getGatewayConfig (n )
54+ config , err := getGatewayConfig (n )
5855 if err != nil {
5956 return nil , err
6057 }
6158
62- gwAPI , err := newGatewayBackend (n )
59+ backend , err := newGatewayBackend (n )
6360 if err != nil {
6461 return nil , err
6562 }
6663
6764 childMux := http .NewServeMux ()
68- mux .HandleFunc ("/" , gateway .WithHostname ( gwConfig , gwAPI , childMux ).ServeHTTP )
65+ mux .HandleFunc ("/" , gateway .NewHostnameHandler ( config , backend , childMux ).ServeHTTP )
6966 return childMux , nil
7067 }
7168}
@@ -111,11 +108,11 @@ func newGatewayBackend(n *core.IpfsNode) (gateway.IPFSBackend, error) {
111108 }
112109 }
113110
114- gw , err := gateway .NewBlocksGateway (bserv , gateway .WithValueStore (vsRouting ), gateway .WithNameSystem (nsys ))
111+ backend , err := gateway .NewBlocksBackend (bserv , gateway .WithValueStore (vsRouting ), gateway .WithNameSystem (nsys ))
115112 if err != nil {
116113 return nil , err
117114 }
118- return & offlineGatewayErrWrapper {gwimpl : gw }, nil
115+ return & offlineGatewayErrWrapper {gwimpl : backend }, nil
119116}
120117
121118type offlineGatewayErrWrapper struct {
@@ -159,10 +156,10 @@ func (o *offlineGatewayErrWrapper) ResolvePath(ctx context.Context, path gateway
159156 return md , err
160157}
161158
162- func (o * offlineGatewayErrWrapper ) GetCAR (ctx context.Context , path gateway.ImmutablePath ) ( gateway.ContentPathMetadata , io.ReadCloser , <- chan error , error ) {
163- md , data , errCh , err := o .gwimpl .GetCAR (ctx , path )
159+ func (o * offlineGatewayErrWrapper ) GetCAR (ctx context.Context , path gateway.ImmutablePath , params gateway.CarParams ) ( io.ReadCloser , error ) {
160+ data , err := o .gwimpl .GetCAR (ctx , path , params )
164161 err = offlineErrWrap (err )
165- return md , data , errCh , err
162+ return data , err
166163}
167164
168165func (o * offlineGatewayErrWrapper ) IsCached (ctx context.Context , path path.Path ) bool {
@@ -191,12 +188,12 @@ var _ gateway.IPFSBackend = (*offlineGatewayErrWrapper)(nil)
191188
192189var defaultPaths = []string {"/ipfs/" , "/ipns/" , "/api/" , "/p2p/" }
193190
194- var subdomainGatewaySpec = & gateway.Specification {
191+ var subdomainGatewaySpec = & gateway.PublicGateway {
195192 Paths : defaultPaths ,
196193 UseSubdomains : true ,
197194}
198195
199- var defaultKnownGateways = map [string ]* gateway.Specification {
196+ var defaultKnownGateways = map [string ]* gateway.PublicGateway {
200197 "localhost" : subdomainGatewaySpec ,
201198}
202199
@@ -218,7 +215,7 @@ func getGatewayConfig(n *core.IpfsNode) (gateway.Config, error) {
218215 Headers : headers ,
219216 DeserializedResponses : cfg .Gateway .DeserializedResponses .WithDefault (config .DefaultDeserializedResponses ),
220217 NoDNSLink : cfg .Gateway .NoDNSLink ,
221- PublicGateways : map [string ]* gateway.Specification {},
218+ PublicGateways : map [string ]* gateway.PublicGateway {},
222219 }
223220
224221 // Add default implicit known gateways, such as subdomain gateway on localhost.
@@ -235,7 +232,7 @@ func getGatewayConfig(n *core.IpfsNode) (gateway.Config, error) {
235232 continue
236233 }
237234
238- gwCfg .PublicGateways [hostname ] = & gateway.Specification {
235+ gwCfg .PublicGateways [hostname ] = & gateway.PublicGateway {
239236 Paths : gw .Paths ,
240237 NoDNSLink : gw .NoDNSLink ,
241238 UseSubdomains : gw .UseSubdomains ,
0 commit comments