1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-09-28 06:46:14 -04:00

Add method, header support to http2 transport

This commit is contained in:
Shelikhoo 2021-03-01 20:48:30 +00:00
parent 957d7791c4
commit 2847bc3271
No known key found for this signature in database
GPG Key ID: C4D5E79D22B25316

View File

@ -94,8 +94,22 @@ func Dial(ctx context.Context, dest net.Destination, streamSettings *internet.Me
opts := pipe.OptionsFromContext(ctx) opts := pipe.OptionsFromContext(ctx)
preader, pwriter := pipe.New(opts...) preader, pwriter := pipe.New(opts...)
breader := &buf.BufferedReader{Reader: preader} breader := &buf.BufferedReader{Reader: preader}
httpMethod := "PUT"
if httpSettings.Method != "" {
httpMethod = httpSettings.Method
}
httpHeaders := make(http.Header)
for _, httpHeader := range httpSettings.Header {
for _, httpHeaderValue := range httpHeader.Value {
httpHeaders.Set(httpHeader.Name, httpHeaderValue)
}
}
request := &http.Request{ request := &http.Request{
Method: "PUT", Method: httpMethod,
Host: httpSettings.getRandomHost(), Host: httpSettings.getRandomHost(),
Body: breader, Body: breader,
URL: &url.URL{ URL: &url.URL{
@ -106,7 +120,7 @@ func Dial(ctx context.Context, dest net.Destination, streamSettings *internet.Me
Proto: "HTTP/2", Proto: "HTTP/2",
ProtoMajor: 2, ProtoMajor: 2,
ProtoMinor: 0, ProtoMinor: 0,
Header: make(http.Header), Header: httpHeaders,
} }
// Disable any compression method from server. // Disable any compression method from server.
request.Header.Set("Accept-Encoding", "identity") request.Header.Set("Accept-Encoding", "identity")