Skip to content

Commit

Permalink
Merge pull request #3 from valyala/master
Browse files Browse the repository at this point in the history
sync
  • Loading branch information
bingoohuang authored Jan 17, 2024
2 parents d1742a6 + c205a25 commit eed376a
Show file tree
Hide file tree
Showing 50 changed files with 755 additions and 374 deletions.
26 changes: 26 additions & 0 deletions .github/workflows/cifuzz.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: CIFuzz
on: [pull_request]
jobs:
Fuzzing:
runs-on: ubuntu-latest
steps:
- name: Build Fuzzers
id: build
uses: google/oss-fuzz/infra/cifuzz/actions/build_fuzzers@master
with:
oss-fuzz-project-name: 'fasthttp'
dry-run: false
language: go
- name: Run Fuzzers
uses: google/oss-fuzz/infra/cifuzz/actions/run_fuzzers@master
with:
oss-fuzz-project-name: 'fasthttp'
fuzz-seconds: 300
dry-run: false
language: go
- name: Upload Crash
uses: actions/upload-artifact@v3
if: failure() && steps.build.outcome == 'success'
with:
name: artifacts
path: ./out/artifacts
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ tags
.vscode
.DS_Store
vendor/
testdata/fuzz
31 changes: 25 additions & 6 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,11 @@ linters:
- gocognit
- goconst
- gocyclo
- godot
- goerr113
- gomnd
- gosec
- inamedparam
- ireturn
- lll
- maintidx
- nakedret
- nestif
Expand All @@ -36,17 +34,13 @@ linters:
- nonamedreturns
- paralleltest
- perfsprint
- revive
- stylecheck
- testableexamples
- testpackage
- thelper
- tparallel
- unparam
- usestdlibvars
- varnamelen
- wastedassign
- whitespace
- wrapcheck
- wsl

Expand All @@ -63,8 +57,33 @@ linters:
- varcheck

linters-settings:
revive:
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md
rules:
- name: use-any
lll:
line-length: 130
stylecheck:
checks: [
"all",
"-ST1000", # at least one file in a package should have a package comment
]
gocritic:
enabled-checks:
- emptyStringTest

issues:
# Show all issues from a linter.
max-issues-per-linter: 0

# Show all issues with the same text.
max-same-issues: 0

include:
- EXC0011 # include issues about comments from `stylecheck`

exclude-rules:
# Exclude some linters from running on tests files.
- path: _test\.go
linters:
- lll
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -600,7 +600,7 @@ This is an **unsafe** way, the result string and `[]byte` buffer share the same

* *Which GO versions are supported by fasthttp?*

Go 1.15.x. Older versions won't be supported.
Go 1.18.x. Older versions won't be supported.

* *Please provide real benchmark data and server information*

Expand Down
8 changes: 4 additions & 4 deletions args.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func ReleaseArgs(a *Args) {
}

var argsPool = &sync.Pool{
New: func() interface{} {
New: func() any {
return &Args{}
},
}
Expand Down Expand Up @@ -118,7 +118,7 @@ func (a *Args) QueryString() []byte {

// Sort sorts Args by key and then value using 'f' as comparison function.
//
// For example args.Sort(bytes.Compare)
// For example args.Sort(bytes.Compare).
func (a *Args) Sort(f func(x, y []byte) int) {
sort.SliceStable(a.args, func(i, j int) bool {
n := f(a.args[i].key, a.args[j].key)
Expand Down Expand Up @@ -229,7 +229,7 @@ func (a *Args) SetBytesKV(key, value []byte) {

// SetNoValue sets only 'key' as argument without the '='.
//
// Only key in argument, like key1&key2
// Only key in argument, like key1&key2.
func (a *Args) SetNoValue(key string) {
a.args = setArg(a.args, key, "", argsNoValue)
}
Expand Down Expand Up @@ -551,7 +551,7 @@ func decodeArgAppend(dst, src []byte) []byte {
return append(dst, src...)
}

idx := 0
var idx int
switch {
case idxPercent == -1:
idx = idxPlus
Expand Down
6 changes: 3 additions & 3 deletions brotli.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,17 +134,17 @@ func WriteBrotliLevel(w io.Writer, p []byte, level int) (int, error) {

var (
stacklessWriteBrotliOnce sync.Once
stacklessWriteBrotliFunc func(ctx interface{}) bool
stacklessWriteBrotliFunc func(ctx any) bool
)

func stacklessWriteBrotli(ctx interface{}) {
func stacklessWriteBrotli(ctx any) {
stacklessWriteBrotliOnce.Do(func() {
stacklessWriteBrotliFunc = stackless.NewFunc(nonblockingWriteBrotli)
})
stacklessWriteBrotliFunc(ctx)
}

func nonblockingWriteBrotli(ctxv interface{}) {
func nonblockingWriteBrotli(ctxv any) {
ctx := ctxv.(*compressCtx)
zw := acquireRealBrotliWriter(ctx.w, ctx.level)

Expand Down
5 changes: 3 additions & 2 deletions bytesconv_table.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 22 additions & 0 deletions bytesconv_table_gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,12 +98,34 @@ func main() {
return a
}()

tcharTable := func() [128]byte {
// Should match net/textproto's validHeaderFieldByte(c byte) bool
// Defined by RFC 9110 5.6.2
// tchar = "!" / "#" / "$" / "%" / "&" / "'" / "*" / "+" / "-" / "." /
// "^" / "_" / "`" / "|" / "~" / DIGIT / ALPHA
var a [128]byte
for _, v := range "!#$%&'*+-.^_`|~" {
a[v] = 1
}
for i := 'a'; i <= 'z'; i++ {
a[i] = 1
}
for i := 'A'; i <= 'Z'; i++ {
a[i] = 1
}
for i := '0'; i <= '9'; i++ {
a[i] = 1
}
return a
}()

w := bytes.NewBufferString(pre)
fmt.Fprintf(w, "const hex2intTable = %q\n", hex2intTable)
fmt.Fprintf(w, "const toLowerTable = %q\n", toLowerTable)
fmt.Fprintf(w, "const toUpperTable = %q\n", toUpperTable)
fmt.Fprintf(w, "const quotedArgShouldEscapeTable = %q\n", quotedArgShouldEscapeTable)
fmt.Fprintf(w, "const quotedPathShouldEscapeTable = %q\n", quotedPathShouldEscapeTable)
fmt.Fprintf(w, "const tcharTable = %q\n", tcharTable)

if err := os.WriteFile("bytesconv_table.go", w.Bytes(), 0o660); err != nil {
log.Fatal(err)
Expand Down
Loading

0 comments on commit eed376a

Please sign in to comment.