@@ -28,22 +28,11 @@ import (
2828
2929func GatewayOption (paths ... string ) ServeOption {
3030 return func (n * core.IpfsNode , _ net.Listener , mux * http.ServeMux ) (* http.ServeMux , error ) {
31- cfg , err := n . Repo . Config ( )
31+ gwConfig , err := getGatewayConfig ( n )
3232 if err != nil {
3333 return nil , err
3434 }
3535
36- headers := make (map [string ][]string , len (cfg .Gateway .HTTPHeaders ))
37- for h , v := range cfg .Gateway .HTTPHeaders {
38- headers [http .CanonicalHeaderKey (h )] = v
39- }
40-
41- gateway .AddAccessControlHeaders (headers )
42-
43- gwConfig := gateway.Config {
44- Headers : headers ,
45- }
46-
4736 gwAPI , err := newGatewayBackend (n )
4837 if err != nil {
4938 return nil , err
@@ -65,7 +54,7 @@ func GatewayOption(paths ...string) ServeOption {
6554
6655func HostnameOption () ServeOption {
6756 return func (n * core.IpfsNode , _ net.Listener , mux * http.ServeMux ) (* http.ServeMux , error ) {
68- cfg , err := n . Repo . Config ( )
57+ gwConfig , err := getGatewayConfig ( n )
6958 if err != nil {
7059 return nil , err
7160 }
@@ -75,9 +64,8 @@ func HostnameOption() ServeOption {
7564 return nil , err
7665 }
7766
78- publicGateways := convertPublicGateways (cfg .Gateway .PublicGateways )
7967 childMux := http .NewServeMux ()
80- mux .HandleFunc ("/" , gateway .WithHostname (childMux , gwAPI , publicGateways , cfg . Gateway . NoDNSLink ).ServeHTTP )
68+ mux .HandleFunc ("/" , gateway .WithHostname (gwConfig , gwAPI , childMux ).ServeHTTP )
8169 return childMux , nil
8270 }
8371}
@@ -212,6 +200,28 @@ var defaultKnownGateways = map[string]*gateway.Specification{
212200 "localhost" : subdomainGatewaySpec ,
213201}
214202
203+ func getGatewayConfig (n * core.IpfsNode ) (gateway.Config , error ) {
204+ cfg , err := n .Repo .Config ()
205+ if err != nil {
206+ return gateway.Config {}, err
207+ }
208+
209+ headers := make (map [string ][]string , len (cfg .Gateway .HTTPHeaders ))
210+ for h , v := range cfg .Gateway .HTTPHeaders {
211+ headers [http .CanonicalHeaderKey (h )] = v
212+ }
213+ gateway .AddAccessControlHeaders (headers )
214+
215+ gwConfig := gateway.Config {
216+ Headers : headers ,
217+ TrustedMode : cfg .Gateway .TrustedMode .WithDefault (config .DefaultTrustedMode ),
218+ NoDNSLink : cfg .Gateway .NoDNSLink ,
219+ PublicGateways : convertPublicGateways (cfg .Gateway .PublicGateways ),
220+ }
221+
222+ return gwConfig , nil
223+ }
224+
215225func convertPublicGateways (publicGateways map [string ]* config.GatewaySpec ) map [string ]* gateway.Specification {
216226 gws := map [string ]* gateway.Specification {}
217227
@@ -234,6 +244,7 @@ func convertPublicGateways(publicGateways map[string]*config.GatewaySpec) map[st
234244 NoDNSLink : gw .NoDNSLink ,
235245 UseSubdomains : gw .UseSubdomains ,
236246 InlineDNSLink : gw .InlineDNSLink .WithDefault (config .DefaultInlineDNSLink ),
247+ TrustedMode : gw .TrustedMode .WithDefault (config .DefaultTrustedMode ),
237248 }
238249 }
239250
0 commit comments