-
Notifications
You must be signed in to change notification settings - Fork 349
Conversation
gambol99
commented
Jul 10, 2018
- adding a request id middleware injection via the --enable-request-id
- fixing up the Makefile
middleware.go
Outdated
return func(next http.Handler) http.Handler { | ||
return http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) { | ||
if v := req.Header.Get(header); v == "" { | ||
req.Header.Set(header, randomString(length)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we need randomString
? IMHO better option is to use some UUID library - maybe github.com/google/uuid
, also caddy uses it: https://github.com/mholt/caddy/blob/master/caddyhttp/requestid/requestid.go
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[jest@starfury keycloak-proxy]$ make bench
--> Running go bench
goos: linux
goarch: amd64
pkg: github.com/gambol99/keycloak-proxy
BenchmarkRandomBytes36-8 10000000 146 ns/op 96 B/op 2 allocs/op
BenchmarkRandomString36-8 10000000 148 ns/op 96 B/op 2 allocs/op
# using google uuid
BenchmarkUUID-8 1000000 1183 ns/op 16 B/op 1 allocs/op
# using a random string
BenchmarkRandomUUID-8 10000000 187 ns/op 80 B/op 2 allocs/op
BenchmarkEncryptDataBlock-8 1000000 2303 ns/op 1200 B/op 7 allocs/op
BenchmarkEncodeText-8 500000 3262 ns/op 2352 B/op 11 allocs/op
BenchmarkDecodeText-8 1000000 1907 ns/op 2208 B/op 10 allocs/op
BenchmarkContainsSubString-8 200000000 7.95 ns/op 0 B/op 0 allocs/op
PASS
ok github.com/gambol99/keycloak-proxy 17.928s
Running both with a 36 character length, it's 10x slower
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
basically i got bored and started messing about and saved 1000ns :-)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 Could you try https://github.com/edwingeng/wuid, pls?
- adding a request id middleware injection via the --enable-request-id - fixing up the Makefile
…one, lose 20ns but hey :-)