mirror of
https://github.com/bitechdev/ResolveSpec.git
synced 2025-12-06 14:26:22 +00:00
UnderlyingRequest and UnderlyingResponseWriter
This commit is contained in:
parent
abd045493a
commit
93df33e274
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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)
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user