@@ -22,6 +22,8 @@ func (s *server) routes() {
2222 go s .mux .HandleFunc ("/erised/info" , s .handleInfo ())
2323 go s .mux .HandleFunc ("/erised/ip" , s .handleIP ())
2424 go s .mux .HandleFunc ("/erised/shutdown" , s .handleShutdown ())
25+ go s .mux .HandleFunc ("/erised/webpage" , s .handleWebPage ())
26+ go s .mux .HandleFunc ("/erised/webpage/{path...}" , s .handleWebPage ())
2527 log .Debug ().Msg ("leaving routes" )
2628}
2729
@@ -247,3 +249,30 @@ func (s *server) handleShutdown() http.HandlerFunc {
247249 log .Debug ().Msg ("leaving handleShutdown" )
248250 }
249251}
252+
253+ func (s * server ) handleWebPage () http.HandlerFunc {
254+ log .Debug ().Msg ("entering handleWebPage" )
255+
256+ return func (res http.ResponseWriter , req * http.Request ) {
257+ log .Info ().
258+ Str ("protocol" , req .Proto ).
259+ Str ("remoteAddress" , req .RemoteAddr ).
260+ Str ("method" , req .Method ).
261+ Str ("host" , req .Host ).
262+ Str ("path" , req .RequestURI ).
263+ Msg ("handleWebPage" )
264+
265+ res .Header ().Set ("Content-Type" , "text/html" )
266+
267+ data := "<!DOCTYPE html><html><head><title>Erised Webpage</title></head>"
268+ data += "<body>"
269+ data += "<center><h1>Host: " + req .Host + "</h1></center>"
270+ data += "<center><h1>Method: " + req .Method + "</h1></center>"
271+ data += "<center><h1>Protocol: " + req .Proto + "</h1></center>"
272+ data += "<center><h1>Request Path: " + req .RequestURI + "</h1></center>"
273+ data += "<hr><center><a href=\" https://github.com/EAddario/erised\" >Erised: A nimble http server to test arbitrary REST API responses.</a></center>"
274+ data += "</body></html>"
275+ s .respond (res , encodingHTML , 0 , data )
276+ log .Debug ().Msg ("leaving handleWebPage" )
277+ }
278+ }
0 commit comments