Skip to content
This repository has been archived by the owner on Dec 7, 2020. It is now read-only.

Request ID #392

Merged
merged 3 commits into from
Jul 11, 2018
Merged

Request ID #392

merged 3 commits into from
Jul 11, 2018

Conversation

gambol99
Copy link
Contributor

  • 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))
Copy link
Contributor

@jangaraj jangaraj Jul 10, 2018

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

Copy link
Contributor Author

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

Copy link
Contributor Author

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 :-)

Copy link
Contributor

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
@gambol99 gambol99 merged commit c4d677a into master Jul 11, 2018
@gambol99 gambol99 deleted the request_id branch July 11, 2018 22:09
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants