ipfs / kubo

An IPFS implementation in Go
https://docs.ipfs.tech/how-to/command-line-quick-start/
Other
16.15k stars 3.01k forks source link

Compressed response from server #4385

Open richardschneider opened 6 years ago

richardschneider commented 6 years ago

Version information:

go-ipfs version: 0.4.11- Repo version: 6 System version: amd64/windows Golang version: go1.9

Type: Enhancement

Description:

Compressing the response from the server can lower bandwidth requirements, especially when transferring large blocks.

The HTTP header Accept-Encoding: gzip should be accepted in a request. The server should then send a compressed response with Content-Encoding: gzip

magik6k commented 5 years ago

If anyone wants to help with this:

Stebalien commented 5 years ago

This would likely be useful for our public gateways. However, it significantly impacts the performance of a local gateway/API (like, 14x+ slowdown).

Stebalien commented 5 years ago
package corehttp

import (
    "github.com/NYTimes/gziphandler"
    "net"
    "net/http"

    core "github.com/ipfs/go-ipfs/core"
)

func CompressOption() ServeOption {
    return func(n *core.IpfsNode, _ net.Listener, mux *http.ServeMux) (*http.ServeMux, error) {
        childMux := http.NewServeMux()
        mux.Handle("/", gziphandler.GzipHandler(childMux))
        return childMux, nil
    }
}