mirror of
https://github.com/snail007/goproxy.git
synced 2026-04-27 08:25:54 +03:00
[GH-ISSUE #504] streamCopy流拷贝之前怎么读取p1(tcp.conn对象)的数据? #406
Labels
No labels
TODO
bug
duplicate
enhancement
good first issue
help wanted
helpful
invalid
need-confirm
pull-request
question
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/goproxy#406
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @seamanm on GitHub (Oct 11, 2022).
Original GitHub issue: https://github.com/snail007/goproxy/issues/504
`
startT := time.Now() //计算当前时间
logln := func(v ...interface{}) {
log.Println(v...)
}
defer p1.Close()
p2, err := session.OpenStream()
if err != nil {
logln(err)
return
}
defer p2.Close()
defer logln("closed", "in:", p1.RemoteAddr(), "out:", fmt.Sprint(p2.RemoteAddr(), "(", p2.ID(), ") time cost:", time.Since(startT)))
streamCopy := func(dst io.Writer, src io.ReadCloser) {
if _, err := generic.Copy(dst, src); err != nil {
if err == smux.ErrInvalidProtocol {
log.Println("smux", err, "in:", p1.RemoteAddr(), "out:", fmt.Sprint(p2.RemoteAddr(), "(", p2.ID(), ")"))
} else {
log.Println(err, "in:", p1.RemoteAddr(), "out:", fmt.Sprint(p2.RemoteAddr(), "(", p2.ID(), ")"))
}
}
}
go streamCopy(p1, p2)
buf := &bytes.Buffer{}
tee := io.TeeReader(p1, buf)
http.ReadRequest(bufio.NewReader(tee))
buf0 := make([]byte, bufSize)
streamCopy(p2, p1)
`
我希望在流拷贝之前,从p1里面读取出数据并根据数据做一些其他事,然后再去p1和p2拷贝流,我不知道该怎么做我现在尝试http.ReadRequest(bufio.NewReader(tee)),但是流拷贝的时候导致http请求失败,我猜是p1里面的数据被读取过了的原因