Skip to content

Commit

Permalink
⛓️‍💥 http: remove linkname to net/http.readRequest
Browse files Browse the repository at this point in the history
In light of golang/go#67401, we are reevaluating uses of go:linkname in our codebase.

The exported ReadRequest function satisfies our needs. There's no point in using the unexported function.
  • Loading branch information
database64128 committed May 20, 2024
1 parent 41b08ff commit 0844083
Showing 1 changed file with 2 additions and 6 deletions.
8 changes: 2 additions & 6 deletions http/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"net/url"
"strings"
"time"
_ "unsafe"

"github.com/database64128/shadowsocks-go/conn"
"github.com/database64128/shadowsocks-go/direct"
Expand All @@ -18,13 +17,10 @@ import (
"go.uber.org/zap"
)

//go:linkname readRequest net/http.readRequest
func readRequest(b *bufio.Reader) (req *http.Request, err error)

// NewHttpStreamServerReadWriter handles a HTTP request from rw and wraps rw into a ReadWriter ready for use.
func NewHttpStreamServerReadWriter(rw zerocopy.DirectReadWriteCloser, logger *zap.Logger) (*direct.DirectStreamReadWriter, conn.Addr, error) {
rwbr := bufio.NewReader(rw)
req, err := readRequest(rwbr)
req, err := http.ReadRequest(rwbr)
if err != nil {
return nil, conn.Addr{}, err
}
Expand Down Expand Up @@ -161,7 +157,7 @@ func NewHttpStreamServerReadWriter(rw zerocopy.DirectReadWriteCloser, logger *za
}

// Read request.
req, werr = readRequest(rwbr)
req, werr = http.ReadRequest(rwbr)
if werr != nil {
if werr != io.EOF {
werr = fmt.Errorf("failed to read HTTP request: %w", werr)
Expand Down

0 comments on commit 0844083

Please sign in to comment.