@@ -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
@@ -67,7 +56,7 @@ func GatewayOption(paths ...string) ServeOption {
6756
6857func HostnameOption () ServeOption {
6958 return func (n * core.IpfsNode , _ net.Listener , mux * http.ServeMux ) (* http.ServeMux , error ) {
70- cfg , err := n . Repo . Config ( )
59+ gwConfig , err := getGatewayConfig ( n )
7160 if err != nil {
7261 return nil , err
7362 }
@@ -77,9 +66,8 @@ func HostnameOption() ServeOption {
7766 return nil , err
7867 }
7968
80- publicGateways := convertPublicGateways (cfg .Gateway .PublicGateways )
8169 childMux := http .NewServeMux ()
82- mux .HandleFunc ("/" , gateway .WithHostname (childMux , gwAPI , publicGateways , cfg . Gateway . NoDNSLink ).ServeHTTP )
70+ mux .HandleFunc ("/" , gateway .WithHostname (gwConfig , gwAPI , childMux ).ServeHTTP )
8371 return childMux , nil
8472 }
8573}
@@ -214,6 +202,28 @@ var defaultKnownGateways = map[string]*gateway.Specification{
214202 "localhost" : subdomainGatewaySpec ,
215203}
216204
205+ func getGatewayConfig (n * core.IpfsNode ) (gateway.Config , error ) {
206+ cfg , err := n .Repo .Config ()
207+ if err != nil {
208+ return gateway.Config {}, err
209+ }
210+
211+ headers := make (map [string ][]string , len (cfg .Gateway .HTTPHeaders ))
212+ for h , v := range cfg .Gateway .HTTPHeaders {
213+ headers [http .CanonicalHeaderKey (h )] = v
214+ }
215+ gateway .AddAccessControlHeaders (headers )
216+
217+ gwConfig := gateway.Config {
218+ Headers : headers ,
219+ TrustedMode : true ,
220+ NoDNSLink : cfg .Gateway .NoDNSLink ,
221+ PublicGateways : convertPublicGateways (cfg .Gateway .PublicGateways ),
222+ }
223+
224+ return gwConfig , nil
225+ }
226+
217227func convertPublicGateways (publicGateways map [string ]* config.GatewaySpec ) map [string ]* gateway.Specification {
218228 gws := map [string ]* gateway.Specification {}
219229
@@ -236,6 +246,7 @@ func convertPublicGateways(publicGateways map[string]*config.GatewaySpec) map[st
236246 NoDNSLink : gw .NoDNSLink ,
237247 UseSubdomains : gw .UseSubdomains ,
238248 InlineDNSLink : gw .InlineDNSLink .WithDefault (config .DefaultInlineDNSLink ),
249+ TrustedMode : true ,
239250 }
240251 }
241252
0 commit comments