mirror of
https://github.com/kataras/iris.git
synced 2025-03-15 08:06:27 +01:00
gofmt -s -w .
Former-commit-id: 6cca675303187f10377a7a713b2e7b3cdf16fd18
This commit is contained in:
parent
c4f5fae561
commit
26c315cdb1
|
@ -4,6 +4,11 @@
|
||||||
|
|
||||||
package context
|
package context
|
||||||
|
|
||||||
|
// ConfigurationReadOnly can be implemented
|
||||||
|
// by Configuration, it's being used inside the Context.
|
||||||
|
// All methods that it contains should be "safe" to be called by the context
|
||||||
|
// at "serve time". A configuration field may be missing when it's not
|
||||||
|
// safe or its useless to be called from a request handler.
|
||||||
type ConfigurationReadOnly interface {
|
type ConfigurationReadOnly interface {
|
||||||
// GetVHost returns the non-exported vhost config field.
|
// GetVHost returns the non-exported vhost config field.
|
||||||
//
|
//
|
||||||
|
|
|
@ -85,6 +85,10 @@ type GzipResponseWriter struct {
|
||||||
|
|
||||||
var _ ResponseWriter = &GzipResponseWriter{}
|
var _ ResponseWriter = &GzipResponseWriter{}
|
||||||
|
|
||||||
|
// BeginGzipResponse accepts a ResponseWriter
|
||||||
|
// and prepares the new gzip response writer.
|
||||||
|
// It's being called per-handler, when caller decide
|
||||||
|
// to change the response writer type.
|
||||||
func (w *GzipResponseWriter) BeginGzipResponse(underline ResponseWriter) {
|
func (w *GzipResponseWriter) BeginGzipResponse(underline ResponseWriter) {
|
||||||
w.ResponseWriter = underline
|
w.ResponseWriter = underline
|
||||||
w.gzipWriter = acquireGzipWriter(w.ResponseWriter)
|
w.gzipWriter = acquireGzipWriter(w.ResponseWriter)
|
||||||
|
@ -92,6 +96,8 @@ func (w *GzipResponseWriter) BeginGzipResponse(underline ResponseWriter) {
|
||||||
w.disabled = false
|
w.disabled = false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// EndResponse called right before the contents of this
|
||||||
|
// response writer are flushed to the client.
|
||||||
func (w *GzipResponseWriter) EndResponse() {
|
func (w *GzipResponseWriter) EndResponse() {
|
||||||
releaseGzipResponseWriter(w)
|
releaseGzipResponseWriter(w)
|
||||||
w.ResponseWriter.EndResponse()
|
w.ResponseWriter.EndResponse()
|
||||||
|
@ -104,6 +110,8 @@ func (w *GzipResponseWriter) Write(contents []byte) (int, error) {
|
||||||
return len(w.chunks), nil
|
return len(w.chunks), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// FlushResponse validates the response headers in order to be compatible with the gzip written data
|
||||||
|
// and writes the data to the underline ResponseWriter.
|
||||||
func (w *GzipResponseWriter) FlushResponse() {
|
func (w *GzipResponseWriter) FlushResponse() {
|
||||||
if w.disabled {
|
if w.disabled {
|
||||||
w.ResponseWriter.Write(w.chunks)
|
w.ResponseWriter.Write(w.chunks)
|
||||||
|
@ -128,7 +136,7 @@ func (w *GzipResponseWriter) ResetBody() {
|
||||||
w.chunks = w.chunks[0:0]
|
w.chunks = w.chunks[0:0]
|
||||||
}
|
}
|
||||||
|
|
||||||
// Disable, disables the gzip compression for the next .Write's data,
|
// Disable turns of the gzip compression for the next .Write's data,
|
||||||
// if called then the contents are being written in plain form.
|
// if called then the contents are being written in plain form.
|
||||||
func (w *GzipResponseWriter) Disable() {
|
func (w *GzipResponseWriter) Disable() {
|
||||||
w.disabled = true
|
w.disabled = true
|
||||||
|
|
|
@ -4,6 +4,23 @@
|
||||||
|
|
||||||
package context
|
package context
|
||||||
|
|
||||||
|
// A Handler responds to an HTTP request.
|
||||||
|
// It writes reply headers and data to the Context.ResponseWriter() and then return.
|
||||||
|
// Returning signals that the request is finished;
|
||||||
|
// it is not valid to use the Context after or concurrently with the completion of the Handler call.
|
||||||
|
//
|
||||||
|
// Depending on the HTTP client software, HTTP protocol version,
|
||||||
|
// and any intermediaries between the client and the Iris server,
|
||||||
|
// it may not be possible to read from the Context.Request().Body after writing to the context.ResponseWriter().
|
||||||
|
// Cautious handlers should read the Context.Request().Body first, and then reply.
|
||||||
|
//
|
||||||
|
// Except for reading the body, handlers should not modify the provided Context.
|
||||||
|
//
|
||||||
|
// If Handler panics, the server (the caller of Handler) assumes that the effect of the panic was isolated to the active request.
|
||||||
|
// It recovers the panic, logs a stack trace to the server error log, and hangs up the connection.
|
||||||
type Handler func(Context)
|
type Handler func(Context)
|
||||||
|
|
||||||
|
// Handlers is just a type of slice of []Handler.
|
||||||
|
//
|
||||||
|
// See `Handler` for more.
|
||||||
type Handlers []Handler
|
type Handlers []Handler
|
||||||
|
|
|
@ -18,7 +18,7 @@ func TestProxy(t *testing.T) {
|
||||||
unexpectedRoute := "unexpected"
|
unexpectedRoute := "unexpected"
|
||||||
|
|
||||||
// proxySrv := iris.New()
|
// proxySrv := iris.New()
|
||||||
u, err := url.Parse("https://localhost")
|
u, err := url.Parse("https://localhost:4444")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("%v while parsing url", err)
|
t.Fatalf("%v while parsing url", err)
|
||||||
}
|
}
|
||||||
|
@ -31,7 +31,7 @@ func TestProxy(t *testing.T) {
|
||||||
// proxySrv.Downgrade(p.ServeHTTP)
|
// proxySrv.Downgrade(p.ServeHTTP)
|
||||||
// go proxySrv.Run(iris.Addr(":80"), iris.WithoutBanner, iris.WithoutInterruptHandler)
|
// go proxySrv.Run(iris.Addr(":80"), iris.WithoutBanner, iris.WithoutInterruptHandler)
|
||||||
|
|
||||||
go host.NewProxy(":80", u).ListenAndServe()
|
go host.NewProxy(":1193", u).ListenAndServe() // should be localhost/127.0.0.1:80 but travis throws permission denied.
|
||||||
|
|
||||||
app := iris.New()
|
app := iris.New()
|
||||||
app.Get("/", func(ctx context.Context) {
|
app.Get("/", func(ctx context.Context) {
|
||||||
|
@ -46,14 +46,14 @@ func TestProxy(t *testing.T) {
|
||||||
ctx.WriteString(unexpectedRoute)
|
ctx.WriteString(unexpectedRoute)
|
||||||
})
|
})
|
||||||
|
|
||||||
l, err := net.Listen("tcp", "localhost:443")
|
l, err := net.Listen("tcp", "localhost:4444") // should be localhost/127.0.0.1:443 but travis throws permission denied.
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("%v while creating tcp4 listener for new tls local test listener", err)
|
t.Fatalf("%v while creating tcp4 listener for new tls local test listener", err)
|
||||||
}
|
}
|
||||||
// main server
|
// main server
|
||||||
go app.Run(iris.Listener(httptest.NewLocalTLSListener(l)), iris.WithoutBanner)
|
go app.Run(iris.Listener(httptest.NewLocalTLSListener(l)), iris.WithoutBanner)
|
||||||
|
|
||||||
e := httptest.NewInsecure(t, httptest.URL("http://localhost"))
|
e := httptest.NewInsecure(t, httptest.URL("http://localhost:1193"))
|
||||||
e.GET("/").Expect().Status(iris.StatusOK).Body().Equal(expectedIndex)
|
e.GET("/").Expect().Status(iris.StatusOK).Body().Equal(expectedIndex)
|
||||||
e.GET("/about").Expect().Status(iris.StatusOK).Body().Equal(expectedAbout)
|
e.GET("/about").Expect().Status(iris.StatusOK).Body().Equal(expectedAbout)
|
||||||
e.GET("/notfound").Expect().Status(iris.StatusNotFound).Body().Equal(unexpectedRoute)
|
e.GET("/notfound").Expect().Status(iris.StatusNotFound).Body().Equal(unexpectedRoute)
|
||||||
|
|
|
@ -24,7 +24,7 @@ func TestMuttable(t *testing.T) {
|
||||||
|
|
||||||
// map
|
// map
|
||||||
|
|
||||||
p.Set("map", map[string]myTestObject{"key 1": myTestObject{"value 1"}, "key 2": myTestObject{"value 2"}})
|
p.Set("map", map[string]myTestObject{"key 1": {"value 1"}, "key 2": {"value 2"}})
|
||||||
vMap := p.Get("map").(map[string]myTestObject)
|
vMap := p.Get("map").(map[string]myTestObject)
|
||||||
vMap["key 1"] = myTestObject{"modified"}
|
vMap["key 1"] = myTestObject{"modified"}
|
||||||
|
|
||||||
|
@ -60,7 +60,7 @@ func TestImmutable(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// map
|
// map
|
||||||
p.SetImmutable("map", map[string]myTestObject{"key 1": myTestObject{"value 1"}, "key 2": myTestObject{"value 2"}})
|
p.SetImmutable("map", map[string]myTestObject{"key 1": {"value 1"}, "key 2": {"value 2"}})
|
||||||
vMap := p.Get("map").(map[string]myTestObject)
|
vMap := p.Get("map").(map[string]myTestObject)
|
||||||
vMap["key 1"] = myTestObject{"modified"}
|
vMap["key 1"] = myTestObject{"modified"}
|
||||||
|
|
||||||
|
|
|
@ -62,6 +62,8 @@ func (r *repository) getAll() []*Route {
|
||||||
return r.routes
|
return r.routes
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// RoutesProvider should be implemented by
|
||||||
|
// iteral which contains the registered routes.
|
||||||
type RoutesProvider interface { // api builder
|
type RoutesProvider interface { // api builder
|
||||||
GetRoutes() []*Route
|
GetRoutes() []*Route
|
||||||
GetRoute(routeName string) *Route
|
GetRoute(routeName string) *Route
|
||||||
|
@ -177,6 +179,8 @@ func (rb *APIBuilder) Party(relativePath string, handlers ...context.Handler) Pa
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Macros returns the macro map which is responsible
|
||||||
|
// to register custom macro functions for all routes.
|
||||||
func (rb *APIBuilder) Macros() *macro.MacroMap {
|
func (rb *APIBuilder) Macros() *macro.MacroMap {
|
||||||
return rb.macros
|
return rb.macros
|
||||||
}
|
}
|
||||||
|
|
|
@ -70,6 +70,8 @@ func (h *routerHandler) addRoute(method, subdomain, path string, handlers contex
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NewDefaultHandler returns the handler which is responsible
|
||||||
|
// to map the request with a route (aka mux implementation).
|
||||||
func NewDefaultHandler() RequestHandler {
|
func NewDefaultHandler() RequestHandler {
|
||||||
h := &routerHandler{}
|
h := &routerHandler{}
|
||||||
return h
|
return h
|
||||||
|
|
|
@ -588,7 +588,7 @@ func TypeByExtension(ext string) (typ string) {
|
||||||
return typ
|
return typ
|
||||||
}
|
}
|
||||||
|
|
||||||
// TypeByFilename, saem as TypeByExtension
|
// TypeByFilename same as TypeByExtension
|
||||||
// but receives a filename path instead.
|
// but receives a filename path instead.
|
||||||
func TypeByFilename(fullFilename string) string {
|
func TypeByFilename(fullFilename string) string {
|
||||||
ext := filepath.Ext(fullFilename)
|
ext := filepath.Ext(fullFilename)
|
||||||
|
|
|
@ -12,6 +12,9 @@ import (
|
||||||
"github.com/kataras/iris/core/router/macro"
|
"github.com/kataras/iris/core/router/macro"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Route contains the information about a registered Route.
|
||||||
|
// If any of the following fields are changed then the
|
||||||
|
// caller should Refresh the router.
|
||||||
type Route struct {
|
type Route struct {
|
||||||
Name string // "userRoute"
|
Name string // "userRoute"
|
||||||
Method string // "GET"
|
Method string // "GET"
|
||||||
|
@ -24,6 +27,11 @@ type Route struct {
|
||||||
FormattedPath string
|
FormattedPath string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NewRoute returns a new route based on its method,
|
||||||
|
// subdomain, the path (unparsed or original),
|
||||||
|
// handlers and the macro container which all routes should share.
|
||||||
|
// It parses the path based on the "macros",
|
||||||
|
// handlers are being changed to validate the macros at serve time, if needed.
|
||||||
func NewRoute(method, subdomain, unparsedPath string,
|
func NewRoute(method, subdomain, unparsedPath string,
|
||||||
handlers context.Handlers, macros *macro.MacroMap) (*Route, error) {
|
handlers context.Handlers, macros *macro.MacroMap) (*Route, error) {
|
||||||
|
|
||||||
|
|
|
@ -12,6 +12,12 @@ import (
|
||||||
"github.com/kataras/iris/core/errors"
|
"github.com/kataras/iris/core/errors"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Router is the "director".
|
||||||
|
// Caller should provide a request handler (router implementation or root handler).
|
||||||
|
// Router is responsible to build the received request handler and run it
|
||||||
|
// to serve requests, based on the received context.Pool.
|
||||||
|
//
|
||||||
|
// User can refresh the router with `RefreshRouter` whenever a route's field is changed by him.
|
||||||
type Router struct {
|
type Router struct {
|
||||||
mu sync.Mutex // for Downgrade, WrapRouter & BuildRouter,
|
mu sync.Mutex // for Downgrade, WrapRouter & BuildRouter,
|
||||||
// not indeed but we don't to risk its usage by third-parties.
|
// not indeed but we don't to risk its usage by third-parties.
|
||||||
|
|
Loading…
Reference in New Issue
Block a user