mirror of
https://github.com/caddyserver/caddy.git
synced 2024-12-23 22:27:38 -05:00
133ed18374
* Create request_id directive #1590 * Address Comments * Fix TestListenerAddrEqual * requestid: Add some tests * Address Comments by tobya * Address Comments
33 lines
652 B
Go
33 lines
652 B
Go
package requestid
|
|
|
|
import (
|
|
"context"
|
|
"net/http"
|
|
"testing"
|
|
|
|
"github.com/mholt/caddy/caddyhttp/httpserver"
|
|
)
|
|
|
|
func TestRequestID(t *testing.T) {
|
|
request, err := http.NewRequest("GET", "http://localhost/", nil)
|
|
if err != nil {
|
|
t.Fatal("Could not create HTTP request:", err)
|
|
}
|
|
|
|
reqid := UUID()
|
|
|
|
c := context.WithValue(request.Context(), httpserver.RequestIDCtxKey, reqid)
|
|
|
|
request = request.WithContext(c)
|
|
|
|
// See caddyhttp/replacer.go
|
|
value, _ := request.Context().Value(httpserver.RequestIDCtxKey).(string)
|
|
|
|
if value == "" {
|
|
t.Fatal("Request ID should not be empty")
|
|
}
|
|
|
|
if value != reqid {
|
|
t.Fatal("Request ID does not match")
|
|
}
|
|
}
|