diff --git a/pkg/common/adapters/router/bunrouter.go b/pkg/common/adapters/router/bunrouter.go index d2d642c..5ae50cf 100644 --- a/pkg/common/adapters/router/bunrouter.go +++ b/pkg/common/adapters/router/bunrouter.go @@ -141,6 +141,12 @@ func (b *BunRouterRequest) AllHeaders() map[string]string { return headers } +// UnderlyingRequest returns the underlying *http.Request +// This is useful when you need to pass the request to other handlers +func (b *BunRouterRequest) UnderlyingRequest() *http.Request { + return b.req.Request +} + // StandardBunRouterAdapter creates routes compatible with standard bunrouter handlers type StandardBunRouterAdapter struct { *BunRouterAdapter diff --git a/pkg/common/interfaces.go b/pkg/common/interfaces.go index f4fdecf..519664b 100644 --- a/pkg/common/interfaces.go +++ b/pkg/common/interfaces.go @@ -122,6 +122,7 @@ type Request interface { PathParam(key string) string QueryParam(key string) string AllQueryParams() map[string]string // Get all query parameters as a map + UnderlyingRequest() *http.Request // Get the underlying *http.Request for forwarding to other handlers } // ResponseWriter interface abstracts HTTP response @@ -130,6 +131,7 @@ type ResponseWriter interface { WriteHeader(statusCode int) Write(data []byte) (int, error) WriteJSON(data interface{}) error + UnderlyingResponseWriter() http.ResponseWriter // Get the underlying http.ResponseWriter for forwarding to other handlers } // HTTPHandlerFunc type for HTTP handlers @@ -164,6 +166,10 @@ func (s *StandardResponseWriter) WriteJSON(data interface{}) error { return json.NewEncoder(s.w).Encode(data) } +func (s *StandardResponseWriter) UnderlyingResponseWriter() http.ResponseWriter { + return s.w +} + // StandardRequest adapts *http.Request to Request interface type StandardRequest struct { r *http.Request @@ -228,6 +234,10 @@ func (s *StandardRequest) AllQueryParams() map[string]string { return params } +func (s *StandardRequest) UnderlyingRequest() *http.Request { + return s.r +} + // TableNameProvider interface for models that provide table names type TableNameProvider interface { TableName() string diff --git a/pkg/restheadspec/query_params_test.go b/pkg/restheadspec/query_params_test.go index 0633c25..ac1beeb 100644 --- a/pkg/restheadspec/query_params_test.go +++ b/pkg/restheadspec/query_params_test.go @@ -1,6 +1,7 @@ package restheadspec import ( + "net/http" "testing" ) @@ -42,6 +43,12 @@ func (m *MockRequest) AllQueryParams() map[string]string { return m.queryParams } +func (m *MockRequest) UnderlyingRequest() *http.Request { + // For testing purposes, return nil + // In real scenarios, you might want to construct a proper http.Request + return nil +} + func TestParseOptionsFromQueryParams(t *testing.T) { handler := NewHandler(nil, nil)