mirror of
https://github.com/ipfs/kubo.git
synced 2026-02-21 10:27:46 +08:00
Updates: * go-kad-dht: Query performance improvements, DHT client fixes, validates records on *local* put. * go-libp2p-swarm/go-libp2p-transport: Timeout improvements. * go-multiaddr-net: Exposes useful Conn methods (CloseWrite, CloseRead, etc.) * go-log: fixes possible panic when enabling/disabling events. * go-multiaddr: fixes possible panic when stringifying malformed multiaddrs, adds support for consuming /p2p/ multiaddrs. fixes #5113 unblocks #4895 License: MIT Signed-off-by: Steven Allen <steven@stebalien.com>
51 lines
1.3 KiB
Go
51 lines
1.3 KiB
Go
package corehttp
|
|
|
|
import (
|
|
"fmt"
|
|
"net"
|
|
"net/http"
|
|
|
|
core "github.com/ipfs/go-ipfs/core"
|
|
coreapi "github.com/ipfs/go-ipfs/core/coreapi"
|
|
config "github.com/ipfs/go-ipfs/repo/config"
|
|
|
|
id "gx/ipfs/QmZ86eLPtXkQ1Dfa992Q8NpXArUoWWh3y728JDcWvzRrvC/go-libp2p/p2p/protocol/identify"
|
|
)
|
|
|
|
type GatewayConfig struct {
|
|
Headers map[string][]string
|
|
Writable bool
|
|
PathPrefixes []string
|
|
}
|
|
|
|
func GatewayOption(writable bool, paths ...string) ServeOption {
|
|
return func(n *core.IpfsNode, _ net.Listener, mux *http.ServeMux) (*http.ServeMux, error) {
|
|
cfg, err := n.Repo.Config()
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
gateway := newGatewayHandler(n, GatewayConfig{
|
|
Headers: cfg.Gateway.HTTPHeaders,
|
|
Writable: writable,
|
|
PathPrefixes: cfg.Gateway.PathPrefixes,
|
|
}, coreapi.NewCoreAPI(n))
|
|
|
|
for _, p := range paths {
|
|
mux.Handle(p+"/", gateway)
|
|
}
|
|
return mux, nil
|
|
}
|
|
}
|
|
|
|
func VersionOption() ServeOption {
|
|
return func(_ *core.IpfsNode, _ net.Listener, mux *http.ServeMux) (*http.ServeMux, error) {
|
|
mux.HandleFunc("/version", func(w http.ResponseWriter, r *http.Request) {
|
|
fmt.Fprintf(w, "Commit: %s\n", config.CurrentCommit)
|
|
fmt.Fprintf(w, "Client Version: %s\n", id.ClientVersion)
|
|
fmt.Fprintf(w, "Protocol Version: %s\n", id.LibP2PVersion)
|
|
})
|
|
return mux, nil
|
|
}
|
|
}
|