mirror of
https://github.com/shtorm-7/sing-box-extended.git
synced 2026-08-01 03:24:15 +03:00
Add xhttp transport
This commit is contained in:
38
transport/v2rayxhttp/writer.go
Normal file
38
transport/v2rayxhttp/writer.go
Normal file
@@ -0,0 +1,38 @@
|
||||
package xhttp
|
||||
|
||||
import (
|
||||
"github.com/sagernet/sing-box/common/xray/buf"
|
||||
"github.com/sagernet/sing-box/common/xray/pipe"
|
||||
)
|
||||
|
||||
// A wrapper around pipe that ensures the size limit is exactly honored.
|
||||
//
|
||||
// The MultiBuffer pipe accepts any single WriteMultiBuffer call even if that
|
||||
// single MultiBuffer exceeds the size limit, and then starts blocking on the
|
||||
// next WriteMultiBuffer call. This means that ReadMultiBuffer can return more
|
||||
// bytes than the size limit. We work around this by splitting a potentially
|
||||
// too large write up into multiple.
|
||||
type uploadWriter struct {
|
||||
*pipe.Writer
|
||||
maxLen int32
|
||||
}
|
||||
|
||||
func (w uploadWriter) Write(b []byte) (int, error) {
|
||||
/*
|
||||
capacity := int(w.maxLen - w.Len())
|
||||
if capacity > 0 && capacity < len(b) {
|
||||
b = b[:capacity]
|
||||
}
|
||||
*/
|
||||
buffer := buf.New()
|
||||
n, err := buffer.Write(b)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
err = w.WriteMultiBuffer([]*buf.Buffer{buffer})
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return n, nil
|
||||
}
|
||||
Reference in New Issue
Block a user