From 69d023fb5309d2593d7fa8eaeece78c04b6c5837 Mon Sep 17 00:00:00 2001 From: Steven Allen Date: Thu, 14 Mar 2019 20:31:46 -0700 Subject: [PATCH] add config options for proxy/subdomain --- gateway.go | 47 +++++++++++++++++++++++++++++++++++++++++------ init.go | 10 ++++++---- 2 files changed, 47 insertions(+), 10 deletions(-) diff --git a/gateway.go b/gateway.go index 017be9b..f0552ac 100644 --- a/gateway.go +++ b/gateway.go @@ -1,11 +1,46 @@ package config +type GatewaySpec struct { + // PathPrefixes list the set of path prefixes that should be handled by + // this gateway. + PathPrefixes []string + + // UseSubdomains indicates whether or not this gateway uses subdomains + // for IPFS resources instead of paths. That is: http://CID.ipfs.GATEWAY/... + // + // If this flag is set, any /ipns/$id and/or /ipfs/$id paths in PathPrefixes + // will be permanently redirected to http://$id.[ipns|ipfs].$gateway/. + // + // We do not support using both paths and subdomains for a single domain + // for security reasons. + UseSubdomains bool + + // RootRedirect is the path to which requests to `/` on this gateway + // should be redirected. + RootRedirect string +} + // Gateway contains options for the HTTP gateway server. type Gateway struct { - HTTPHeaders map[string][]string // HTTP headers to return with the gateway - RootRedirect string - Writable bool - PathPrefixes []string - APICommands []string - NoFetch bool + + // HTTPHeaders configures the headers that should be returned by this + // gateway. + HTTPHeaders map[string][]string // HTTP headers to return with the gateway + + // Writable enables PUT/POST request handling by this gateway. Usually, + // writing is done through the API, not the gateway. + Writable bool + + // FIXME: Not yet implemented + APICommands []string + + // NoFetch configures the gateway to _not_ fetch blocks in response to + // requests. + NoFetch bool + + // GatewaySpec configures the default behavior for this gateway. + GatewaySpec + + // PublicGateways configures behavior of known public gateways. + PublicGateways map[string]*GatewaySpec } diff --git a/init.go b/init.go index 54e862f..260e7dc 100644 --- a/init.go +++ b/init.go @@ -57,10 +57,12 @@ func Init(out io.Writer, nBitsForKeypair int) (*Config, error) { }, Gateway: Gateway{ - RootRedirect: "", - Writable: false, - NoFetch: false, - PathPrefixes: []string{}, + GatewaySpec: GatewaySpec{ + RootRedirect: "", + PathPrefixes: []string{}, + }, + Writable: false, + NoFetch: false, HTTPHeaders: map[string][]string{ "Access-Control-Allow-Origin": []string{"*"}, "Access-Control-Allow-Methods": []string{"GET"},