diff --git a/app/http/middleware/api.go b/app/http/middleware/api.go index 3b189ca..2b08cf2 100644 --- a/app/http/middleware/api.go +++ b/app/http/middleware/api.go @@ -7,5 +7,5 @@ import ( ) var Api = []inter.HttpMiddleware{ - middleware.DefaultResponseEncoder{Encoder: outcome.Json}, + middleware.DefaultResponseOutcome{Outcome: outcome.Json}, } diff --git a/app/http/middleware/web.go b/app/http/middleware/web.go index ed0c421..c1fa69b 100644 --- a/app/http/middleware/web.go +++ b/app/http/middleware/web.go @@ -7,5 +7,5 @@ import ( ) var Web = []inter.HttpMiddleware{ - middleware.DefaultResponseEncoder{Encoder: outcome.Html}, + middleware.DefaultResponseOutcome{Outcome: outcome.Html}, } diff --git a/app/providers/response_service_provider.go b/app/providers/response_service_provider.go index 03ae4be..49f198e 100644 --- a/app/providers/response_service_provider.go +++ b/app/providers/response_service_provider.go @@ -40,5 +40,10 @@ func (c ResponseServiceProvider) Register(container inter.Container) inter.Conta encoder.InterfaceToJson{}, }) + container.Bind("outcome_content_encoders", []inter.Encoder{ + // add your custom Content encoders here + encoder.StringToString{}, + }) + return container } diff --git a/main.go b/main.go index 08bf775..c35028a 100755 --- a/main.go +++ b/main.go @@ -6,6 +6,7 @@ import ( "lanvard/bootstrap" "log" net "net/http" + "strings" "time" ) @@ -67,10 +68,17 @@ func HandleKernel(response net.ResponseWriter, request *net.Request) { kernel := app.Make((*inter.HttpKernel)(nil)).(http.Kernel) appResponse := kernel.Handle(http.NewRequest(http.Options{App: app, Source: *request})) + // Add HTTP headers + for key, values := range appResponse.GetHeaders() { + response.Header().Add(key, strings.Join(values, "; ")) + } + + // Add HTTP status response.WriteHeader(appResponse.GetStatus()) + + // Add HTTP body _, err := response.Write([]byte(appResponse.GetBody())) if err != nil { panic(err) } - // todo convert custom 'buffer' response headers to default go response } diff --git a/routes/web.go b/routes/web.go index 2d3aed6..3eb8e97 100644 --- a/routes/web.go +++ b/routes/web.go @@ -18,5 +18,4 @@ import ( */ var Web = Group( Get("/", controller.Homepage), - Post("/", controller.Homepage), ).Middleware(middleware.Web...)