Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit27c8345

Browse files
authored
chore: Add linter rule to prevent breaking of sse (#4144)
* chore: Add linter rule to prevent breaking of sse
1 parent5a449bf commit27c8345

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

‎scripts/rules.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ package gorules
1717

1818
import (
1919
"github.com/quasilyte/go-ruleguard/dsl"
20+
"github.com/quasilyte/go-ruleguard/dsl/types"
2021
)
2122

2223
// Use xerrors everywhere! It provides additional stacktrace info!
@@ -238,3 +239,30 @@ func ProperRBACReturn(m dsl.Matcher) {
238239
}
239240
`).Report("Must write to 'ResponseWriter' before returning'")
240241
}
242+
243+
// FullResponseWriter ensures that any overridden response writer has full
244+
// functionality. Mainly is hijackable and flushable.
245+
funcFullResponseWriter(m dsl.Matcher) {
246+
m.Match(`
247+
type $w struct {
248+
$*_
249+
http.ResponseWriter
250+
$*_
251+
}
252+
`).
253+
At(m["w"]).
254+
Where(m["w"].Filter(notImplementsFullResponseWriter)).
255+
Report("ResponseWriter\"$w\" must implement http.Flusher and http.Hijacker")
256+
}
257+
258+
// notImplementsFullResponseWriter returns false if the type does not implement
259+
// http.Flusher, http.Hijacker, and http.ResponseWriter.
260+
funcnotImplementsFullResponseWriter(ctx*dsl.VarFilterContext)bool {
261+
flusher:=ctx.GetInterface(`net/http.Flusher`)
262+
hijacker:=ctx.GetInterface(`net/http.Hijacker`)
263+
writer:=ctx.GetInterface(`net/http.ResponseWriter`)
264+
p:=types.NewPointer(ctx.Type)
265+
return!(types.Implements(p,writer)||types.Implements(ctx.Type,writer))||
266+
!(types.Implements(p,flusher)||types.Implements(ctx.Type,flusher))||
267+
!(types.Implements(p,hijacker)||types.Implements(ctx.Type,hijacker))
268+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp