Skip to content

Commit

Permalink
Merge pull request ipfs/kubo#9023 from ipfs/release-v0.13.0
Browse files Browse the repository at this point in the history
Release v0.13.0

This commit was moved from ipfs/kubo@c9d51bb
  • Loading branch information
guseggert committed Jun 9, 2022
2 parents 2f94345 + 0f6329e commit 444e066
Show file tree
Hide file tree
Showing 14 changed files with 1,168 additions and 458 deletions.
14 changes: 9 additions & 5 deletions gateway/core/corehttp/commands.go
Expand Up @@ -16,7 +16,7 @@ import (

cmds "github.com/ipfs/go-ipfs-cmds"
cmdsHttp "github.com/ipfs/go-ipfs-cmds/http"
config "github.com/ipfs/go-ipfs-config"
config "github.com/ipfs/go-ipfs/config"
path "github.com/ipfs/go-path"
)

Expand Down Expand Up @@ -46,6 +46,11 @@ var defaultLocalhostOrigins = []string{
"https://localhost:<port>",
}

var companionBrowserExtensionOrigins = []string{
"chrome-extension://nibjojkomfdiaoajekhjakgkdhaomnch", // ipfs-companion
"chrome-extension://hjoieblefckbooibpepigmacodalfndh", // ipfs-companion-beta
}

func addCORSFromEnv(c *cmdsHttp.ServerConfig) {
origin := os.Getenv(originEnvKey)
if origin != "" {
Expand Down Expand Up @@ -84,10 +89,9 @@ func addHeadersFromConfig(c *cmdsHttp.ServerConfig, nc *config.Config) {
}

func addCORSDefaults(c *cmdsHttp.ServerConfig) {
// by default use localhost origins
if len(c.AllowedOrigins()) == 0 {
c.SetAllowedOrigins(defaultLocalhostOrigins...)
}
// always safelist certain origins
c.AppendAllowedOrigins(defaultLocalhostOrigins...)
c.AppendAllowedOrigins(companionBrowserExtensionOrigins...)

// by default, use GET, PUT, POST
if len(c.AllowedMethods()) == 0 {
Expand Down
22 changes: 15 additions & 7 deletions gateway/core/corehttp/gateway.go
Expand Up @@ -9,15 +9,17 @@ import (
version "github.com/ipfs/go-ipfs"
core "github.com/ipfs/go-ipfs/core"
coreapi "github.com/ipfs/go-ipfs/core/coreapi"
"go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp"

options "github.com/ipfs/interface-go-ipfs-core/options"
id "github.com/libp2p/go-libp2p/p2p/protocol/identify"
)

type GatewayConfig struct {
Headers map[string][]string
Writable bool
PathPrefixes []string
Headers map[string][]string
Writable bool
PathPrefixes []string
FastDirIndexThreshold int
}

// A helper function to clean up a set of headers:
Expand Down Expand Up @@ -82,17 +84,23 @@ func GatewayOption(writable bool, paths ...string) ServeOption {

headers[ACEHeadersName] = cleanHeaderSet(
append([]string{
"Content-Length",
"Content-Range",
"X-Chunked-Output",
"X-Stream-Output",
"X-Ipfs-Path",
"X-Ipfs-Roots",
}, headers[ACEHeadersName]...))

gateway := newGatewayHandler(GatewayConfig{
Headers: headers,
Writable: writable,
PathPrefixes: cfg.Gateway.PathPrefixes,
var gateway http.Handler = newGatewayHandler(GatewayConfig{
Headers: headers,
Writable: writable,
PathPrefixes: cfg.Gateway.PathPrefixes,
FastDirIndexThreshold: int(cfg.Gateway.FastDirIndexThreshold.WithDefault(100)),
}, api)

gateway = otelhttp.NewHandler(gateway, "Gateway.Request")

for _, p := range paths {
mux.Handle(p+"/", gateway)
}
Expand Down

0 comments on commit 444e066

Please sign in to comment.