Skip to content

Commit 646b194

Browse files
mattnhoisie
authored andcommitted
Add web.Process and web.Server.Process
These invoke the routing system directly. They can be used for testing, as well as processing HTTP requests that are constructed from other sources.
1 parent 0e30b3f commit 646b194

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

web.go

+13-2
Original file line numberDiff line numberDiff line change
@@ -234,9 +234,14 @@ func (c *responseWriter) Close() {
234234
}
235235
}
236236

237+
// ServeHTTP is the interface method for Go's http server package
237238
func (s *Server) ServeHTTP(c http.ResponseWriter, req *http.Request) {
238-
w := responseWriter{c}
239-
s.routeHandler(req, &w)
239+
s.Process(c, req)
240+
}
241+
242+
// Process invokes the main server's routing system.
243+
func Process(c http.ResponseWriter, req *http.Request) {
244+
mainServer.Process(c, req)
240245
}
241246

242247
// safelyCall invokes `function` in recover block
@@ -423,6 +428,12 @@ func (s *Server) initServer() {
423428
}
424429
}
425430

431+
// Process invokes the routing system for server s
432+
func (s *Server) Process(c http.ResponseWriter, req *http.Request) {
433+
w := responseWriter{c}
434+
s.routeHandler(req, &w)
435+
}
436+
426437
// Run starts the web application and serves HTTP requests for s
427438
func (s *Server) Run(addr string) {
428439
s.initServer()

web_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ func getTestResponse(method string, path string, body string, headers map[string
9393

9494
tcpb := tcpBuffer{nil, &buf}
9595
c := scgiConn{wroteHeaders: false, req: req, headers: make(map[string][]string), fd: &tcpb}
96-
mainServer.routeHandler(req, &c)
96+
mainServer.Process(&c, req)
9797
return buildTestResponse(&buf)
9898
}
9999

0 commit comments

Comments
 (0)