Skip to content

Commit

Permalink
修复FLOW_CONTROL_ERROR错误,修复python调用post时报错,禁止json.Marshal对 '<', '>', '&…
Browse files Browse the repository at this point in the history
…'等字符进行HTML编码
  • Loading branch information
wangluozhe committed Oct 12, 2023
1 parent 00431a8 commit 2403fb5
Show file tree
Hide file tree
Showing 10 changed files with 28 additions and 14 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# requests
[![Gitee link address](https://img.shields.io/badge/gitee-reference-red?logo=gitee&logoColor=red&labelColor=white)](https://gitee.com/leegene/requests)[![Github link address](https://img.shields.io/badge/github-reference-blue?logo=github&logoColor=black&labelColor=white&color=black)](https://github.com/wangluozhe/requests)[![Go Version](https://img.shields.io/badge/Go%20Version-1.20-blue?logo=go&logoColor=white&labelColor=gray)]()[![Release Version](https://img.shields.io/badge/release-v1.1.18-blue)]()[![go documentation](https://img.shields.io/badge/go-documentation-blue)](https://pkg.go.dev/github.com/wangluozhe/requests)[![license GPL-3.0](https://img.shields.io/badge/license-GPL3.0-orange)](https://github.com/wangluozhe/requests/blob/main/LICENSE)
[![Gitee link address](https://img.shields.io/badge/gitee-reference-red?logo=gitee&logoColor=red&labelColor=white)](https://gitee.com/leegene/requests)[![Github link address](https://img.shields.io/badge/github-reference-blue?logo=github&logoColor=black&labelColor=white&color=black)](https://github.com/wangluozhe/requests)[![Go Version](https://img.shields.io/badge/Go%20Version-1.20-blue?logo=go&logoColor=white&labelColor=gray)]()[![Release Version](https://img.shields.io/badge/release-v1.1.19-blue)]()[![go documentation](https://img.shields.io/badge/go-documentation-blue)](https://pkg.go.dev/github.com/wangluozhe/requests)[![license GPL-3.0](https://img.shields.io/badge/license-GPL3.0-orange)](https://github.com/wangluozhe/requests/blob/main/LICENSE)

requests支持以下新特性:

Expand Down Expand Up @@ -28,7 +28,7 @@ go get github.com/wangluozhe/requests
## 下载指定版

```bash
go get github.com/wangluozhe/requests@v1.1.17
go get github.com/wangluozhe/requests@v1.1.19
```


Expand Down
5 changes: 2 additions & 3 deletions libs_dist/build_amd64_so.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
# apt-get install gcc-10-aarch64-linux-gnu
# build arm64 so
GOOS=linux CGO_ENABLED=1 GOARCH=arm64 CC="aarch64-linux-gnu-gcc-10" go build -buildmode=c-shared -o requests-go-arm64.so export.go
# build amd64 so
GOOS=linux GOARCH=amd64 go build -buildmode=c-shared -o requests-go-amd64.so export.go
3 changes: 2 additions & 1 deletion libs_dist/build_arm64_so.sh
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
# apt-get install gcc-10-aarch64-linux-gnu
# build arm64 so
GOOS=linux GOARCH=arm64 go build -buildmode=c-shared -o requests-go-arm64.so export.go
GOOS=linux CGO_ENABLED=1 GOARCH=arm64 CC="aarch64-linux-gnu-gcc-10" go build -buildmode=c-shared -o requests-go-arm64.so export.go
2 changes: 1 addition & 1 deletion libs_dist/build_x86_dylib.sh
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# build x86 dylib
GOOS=darwin GOARCH=386 go build -buildmode=c-shared -o requests-go-x86.dylib export.go
GOOS=darwin GOARCH=amd64 go build -buildmode=c-shared -o requests-go-x86.dylib export.go
2 changes: 1 addition & 1 deletion libs_dist/build_x86_so.sh
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# build x86 so
GOOS=linux GOARCH=386 go build -buildmode=c-shared -o requests-go-x86.so export.go
GOOS=linux GOARCH=amd64 go build -buildmode=c-shared -o requests-go-x86.so export.go
5 changes: 4 additions & 1 deletion libs_dist/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
ja3 "github.com/wangluozhe/requests/transport"
"github.com/wangluozhe/requests/url"
url2 "net/url"
"strings"
"sync"
"time"
"unsafe"
Expand Down Expand Up @@ -94,7 +95,9 @@ func buildRequest(requestParams libs.RequestParams) (*url.Request, *C.char) {
if requestParams.Headers != nil {
headers := url.NewHeaders()
for key, value := range requestParams.Headers {
headers.Set(key, value)
if strings.ToLower(key) != "content-length" {
headers.Set(key, value)
}
}
req.Headers = headers
if requestParams.HeadersOrder != nil {
Expand Down
4 changes: 2 additions & 2 deletions models/PrepareRequest.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package models
import (
"bytes"
"encoding/base64"
jsonp "encoding/json"
"errors"
"fmt"
"github.com/wangluozhe/fhttp"
Expand Down Expand Up @@ -139,7 +138,8 @@ func (pr *PrepareRequest) Prepare_body(data *url.Values, files *url.Files, json
}
if data == nil && json != nil {
content_type = "application/json"
json_byte, err := jsonp.Marshal(json)
json_byte, err := utils.Marshal(json) // 避免json.Marshal对 "<", ">", "&" 等字符进行HTML编码
//json_byte, err := jsonp.Marshal(json)
if err != nil {
return err
}
Expand Down
4 changes: 2 additions & 2 deletions transport/roundtripper.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,8 @@ func (rt *roundTripper) dialTLS(ctx context.Context, network, addr string) (net.
} else {
t2.StrictMaxConcurrentStreams = false
}
case http2.SettingInitialWindowSize:
t2.InitialWindowSize = v.Val
//case http2.SettingInitialWindowSize:
// t2.InitialWindowSize = v.Val
case http2.SettingMaxHeaderListSize:
t2.MaxHeaderListSize = v.Val
}
Expand Down
11 changes: 11 additions & 0 deletions utils/code.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"encoding/base64"
"encoding/binary"
"encoding/hex"
"encoding/json"
"errors"
"net/url"
"regexp"
Expand Down Expand Up @@ -179,3 +180,13 @@ func UnEscape(s interface{}) string {
str = DecodeURIComponent(str)
return str
}

// Marshal 避免json.Marshal对 "<", ">", "&" 等字符进行HTML编码
func Marshal(data interface{}) ([]byte, error) {
var buffer bytes.Buffer
encoder := json.NewEncoder(&buffer)
// 禁用HTML转义
encoder.SetEscapeHTML(false)
err := encoder.Encode(data)
return buffer.Bytes(), err
}
2 changes: 1 addition & 1 deletion version.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ package requests

const (
NAME = "golang-requests" // 名称
VERSION = "1.1.18" // 当前版本
VERSION = "1.1.19" // 当前版本
USER_AGENT = NAME + VERSION // UA
)

0 comments on commit 2403fb5

Please sign in to comment.