1
0
mirror of https://github.com/gofiber/fiber.git synced 2025-02-23 18:43:49 +00:00

Merge pull request #7 from gofiber/master

Accumulative update @ 15 Apr 2020
This commit is contained in:
Vic Shóstak 2020-04-15 10:56:56 +03:00 committed by GitHub
commit 08b3a13e05
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
18 changed files with 370 additions and 76 deletions

24
.github/README.md vendored
View File

@ -157,8 +157,8 @@ func main() {
})
// GET /api/register
app.Get("/api*", func(c *fiber.Ctx) {
fmt.Printf("/api%s", c.Params("*"))
app.Get("/api/*", func(c *fiber.Ctx) {
fmt.Printf("/api/%s", c.Params("*"))
// => /api/register
})
@ -507,10 +507,28 @@ If you want to say **thank you** and/or support the active development of `Fiber
<table>
<tr>
<td align="center">
<a href="https://github.com/raymayemir">
<img src="https://avatars2.githubusercontent.com/u/5638101?s=460&v=4" width="100px"></br>
<sub><b>Ray Mayemir</b></sub>
</a>
</td>
<td align="center">
<a href="https://github.com/melkorm">
<img src="https://avatars2.githubusercontent.com/u/619996?s=460&v=4" width="100px"></br>
<sub><b>melkorm</b></sub>
</a>
</td>
<td align="center">
<a href="https://github.com/ekaputra07">
<img src="https://avatars3.githubusercontent.com/u/1094221?s=460&v=4" width="100px"></br>
<sub><b>Eka Putra</b></sub>
</a>
</td>
<td align="center">
<a href="https://github.com/bihe">
<img src="https://avatars1.githubusercontent.com/u/635852?s=460&v=4" width="100px"></br>
<sub><b>HenrikBinggl</b></sub>
<sub><b>Henrik Binggl</b></sub>
</a>
</td>
<td align="center">

24
.github/README_de.md vendored
View File

@ -156,8 +156,8 @@ func main() {
})
// GET /api/register
app.Get("/api*", func(c *fiber.Ctx) {
fmt.Printf("/api%s", c.Params("*"))
app.Get("/api/*", func(c *fiber.Ctx) {
fmt.Printf("/api/%s", c.Params("*"))
// => /api/register
})
@ -505,10 +505,28 @@ Falls du **danke** sagen möchtest und/oder aktiv die Entwicklung von `fiber` f
<table>
<tr>
<td align="center">
<a href="https://github.com/raymayemir">
<img src="https://avatars2.githubusercontent.com/u/5638101?s=460&v=4" width="100px"></br>
<sub><b>Ray Mayemir</b></sub>
</a>
</td>
<td align="center">
<a href="https://github.com/melkorm">
<img src="https://avatars2.githubusercontent.com/u/619996?s=460&v=4" width="100px"></br>
<sub><b>melkorm</b></sub>
</a>
</td>
<td align="center">
<a href="https://github.com/ekaputra07">
<img src="https://avatars3.githubusercontent.com/u/1094221?s=460&v=4" width="100px"></br>
<sub><b>Eka Putra</b></sub>
</a>
</td>
<td align="center">
<a href="https://github.com/bihe">
<img src="https://avatars1.githubusercontent.com/u/635852?s=460&v=4" width="100px"></br>
<sub><b>HenrikBinggl</b></sub>
<sub><b>Henrik Binggl</b></sub>
</a>
</td>
<td align="center">

24
.github/README_es.md vendored
View File

@ -156,8 +156,8 @@ func main() {
})
// GET /api/register
app.Get("/api*", func(c *fiber.Ctx) {
fmt.Printf("/api%s", c.Params("*"))
app.Get("/api/*", func(c *fiber.Ctx) {
fmt.Printf("/api/%s", c.Params("*"))
// => /api/register
})
@ -486,10 +486,28 @@ Si quiere **agradecer** y/o apoyar el desarrollo activo de la `Fiber`:
<table>
<tr>
<td align="center">
<a href="https://github.com/raymayemir">
<img src="https://avatars2.githubusercontent.com/u/5638101?s=460&v=4" width="100px"></br>
<sub><b>Ray Mayemir</b></sub>
</a>
</td>
<td align="center">
<a href="https://github.com/melkorm">
<img src="https://avatars2.githubusercontent.com/u/619996?s=460&v=4" width="100px"></br>
<sub><b>melkorm</b></sub>
</a>
</td>
<td align="center">
<a href="https://github.com/ekaputra07">
<img src="https://avatars3.githubusercontent.com/u/1094221?s=460&v=4" width="100px"></br>
<sub><b>Eka Putra</b></sub>
</a>
</td>
<td align="center">
<a href="https://github.com/bihe">
<img src="https://avatars1.githubusercontent.com/u/635852?s=460&v=4" width="100px"></br>
<sub><b>HenrikBinggl</b></sub>
<sub><b>Henrik Binggl</b></sub>
</a>
</td>
<td align="center">

24
.github/README_fr.md vendored
View File

@ -156,8 +156,8 @@ func main() {
})
// GET /api/register
app.Get("/api*", func(c *fiber.Ctx) {
fmt.Printf("/api%s", c.Params("*"))
app.Get("/api/*", func(c *fiber.Ctx) {
fmt.Printf("/api/%s", c.Params("*"))
// => /api/register
})
@ -486,10 +486,28 @@ Si vous voulez nous remercier et/ou soutenir le développement actif de `Fiber`:
<table>
<tr>
<td align="center">
<a href="https://github.com/raymayemir">
<img src="https://avatars2.githubusercontent.com/u/5638101?s=460&v=4" width="100px"></br>
<sub><b>Ray Mayemir</b></sub>
</a>
</td>
<td align="center">
<a href="https://github.com/melkorm">
<img src="https://avatars2.githubusercontent.com/u/619996?s=460&v=4" width="100px"></br>
<sub><b>melkorm</b></sub>
</a>
</td>
<td align="center">
<a href="https://github.com/ekaputra07">
<img src="https://avatars3.githubusercontent.com/u/1094221?s=460&v=4" width="100px"></br>
<sub><b>Eka Putra</b></sub>
</a>
</td>
<td align="center">
<a href="https://github.com/bihe">
<img src="https://avatars1.githubusercontent.com/u/635852?s=460&v=4" width="100px"></br>
<sub><b>HenrikBinggl</b></sub>
<sub><b>Henrik Binggl</b></sub>
</a>
</td>
<td align="center">

24
.github/README_id.md vendored
View File

@ -158,8 +158,8 @@ func main() {
})
// GET /api/register
app.Get("/api*", func(c *fiber.Ctx) {
fmt.Printf("/api%s", c.Params("*"))
app.Get("/api/*", func(c *fiber.Ctx) {
fmt.Printf("/api/%s", c.Params("*"))
// => /api/register
})
@ -489,10 +489,28 @@ Apabila anda ingin mengucapkan **terima kasih** dan/atau mendukung pengembangan
<table>
<tr>
<td align="center">
<a href="https://github.com/raymayemir">
<img src="https://avatars2.githubusercontent.com/u/5638101?s=460&v=4" width="100px"></br>
<sub><b>Ray Mayemir</b></sub>
</a>
</td>
<td align="center">
<a href="https://github.com/melkorm">
<img src="https://avatars2.githubusercontent.com/u/619996?s=460&v=4" width="100px"></br>
<sub><b>melkorm</b></sub>
</a>
</td>
<td align="center">
<a href="https://github.com/ekaputra07">
<img src="https://avatars3.githubusercontent.com/u/1094221?s=460&v=4" width="100px"></br>
<sub><b>Eka Putra</b></sub>
</a>
</td>
<td align="center">
<a href="https://github.com/bihe">
<img src="https://avatars1.githubusercontent.com/u/635852?s=460&v=4" width="100px"></br>
<sub><b>HenrikBinggl</b></sub>
<sub><b>Henrik Binggl</b></sub>
</a>
</td>
<td align="center">

24
.github/README_ja.md vendored
View File

@ -160,8 +160,8 @@ func main() {
})
// GET /api/register
app.Get("/api*", func(c *fiber.Ctx) {
fmt.Printf("/api%s", c.Params("*"))
app.Get("/api/*", func(c *fiber.Ctx) {
fmt.Printf("/api/%s", c.Params("*"))
// => /api/register
})
@ -492,10 +492,28 @@ func main() {
<table>
<tr>
<td align="center">
<a href="https://github.com/raymayemir">
<img src="https://avatars2.githubusercontent.com/u/5638101?s=460&v=4" width="100px"></br>
<sub><b>Ray Mayemir</b></sub>
</a>
</td>
<td align="center">
<a href="https://github.com/melkorm">
<img src="https://avatars2.githubusercontent.com/u/619996?s=460&v=4" width="100px"></br>
<sub><b>melkorm</b></sub>
</a>
</td>
<td align="center">
<a href="https://github.com/ekaputra07">
<img src="https://avatars3.githubusercontent.com/u/1094221?s=460&v=4" width="100px"></br>
<sub><b>Eka Putra</b></sub>
</a>
</td>
<td align="center">
<a href="https://github.com/bihe">
<img src="https://avatars1.githubusercontent.com/u/635852?s=460&v=4" width="100px"></br>
<sub><b>HenrikBinggl</b></sub>
<sub><b>Henrik Binggl</b></sub>
</a>
</td>
<td align="center">

24
.github/README_ko.md vendored
View File

@ -160,8 +160,8 @@ func main() {
})
// GET /api/register
app.Get("/api*", func(c *fiber.Ctx) {
fmt.Printf("/api%s", c.Params("*"))
app.Get("/api/*", func(c *fiber.Ctx) {
fmt.Printf("/api/%s", c.Params("*"))
// => /api/register
})
@ -490,10 +490,28 @@ func main() {
<table>
<tr>
<td align="center">
<a href="https://github.com/raymayemir">
<img src="https://avatars2.githubusercontent.com/u/5638101?s=460&v=4" width="100px"></br>
<sub><b>Ray Mayemir</b></sub>
</a>
</td>
<td align="center">
<a href="https://github.com/melkorm">
<img src="https://avatars2.githubusercontent.com/u/619996?s=460&v=4" width="100px"></br>
<sub><b>melkorm</b></sub>
</a>
</td>
<td align="center">
<a href="https://github.com/ekaputra07">
<img src="https://avatars3.githubusercontent.com/u/1094221?s=460&v=4" width="100px"></br>
<sub><b>Eka Putra</b></sub>
</a>
</td>
<td align="center">
<a href="https://github.com/bihe">
<img src="https://avatars1.githubusercontent.com/u/635852?s=460&v=4" width="100px"></br>
<sub><b>HenrikBinggl</b></sub>
<sub><b>Henrik Binggl</b></sub>
</a>
</td>
<td align="center">

24
.github/README_pt.md vendored
View File

@ -156,8 +156,8 @@ func main() {
})
// GET /api/register
app.Get("/api*", func(c *fiber.Ctx) {
fmt.Printf("/api%s", c.Params("*"))
app.Get("/api/*", func(c *fiber.Ctx) {
fmt.Printf("/api/%s", c.Params("*"))
// => /api/register
})
@ -486,10 +486,28 @@ Se você quer **agradecer** e/ou apoiar o desenvolvimento ativo do `Fiber`:
<table>
<tr>
<td align="center">
<a href="https://github.com/raymayemir">
<img src="https://avatars2.githubusercontent.com/u/5638101?s=460&v=4" width="100px"></br>
<sub><b>Ray Mayemir</b></sub>
</a>
</td>
<td align="center">
<a href="https://github.com/melkorm">
<img src="https://avatars2.githubusercontent.com/u/619996?s=460&v=4" width="100px"></br>
<sub><b>melkorm</b></sub>
</a>
</td>
<td align="center">
<a href="https://github.com/ekaputra07">
<img src="https://avatars3.githubusercontent.com/u/1094221?s=460&v=4" width="100px"></br>
<sub><b>Eka Putra</b></sub>
</a>
</td>
<td align="center">
<a href="https://github.com/bihe">
<img src="https://avatars1.githubusercontent.com/u/635852?s=460&v=4" width="100px"></br>
<sub><b>HenrikBinggl</b></sub>
<sub><b>Henrik Binggl</b></sub>
</a>
</td>
<td align="center">

24
.github/README_ru.md vendored
View File

@ -158,8 +158,8 @@ func main() {
})
// GET /api/register
app.Get("/api*", func(c *fiber.Ctx) {
fmt.Printf("/api%s", c.Params("*"))
app.Get("/api/*", func(c *fiber.Ctx) {
fmt.Printf("/api/%s", c.Params("*"))
// => /api/register
})
@ -507,10 +507,28 @@ func main() {
<table>
<tr>
<td align="center">
<a href="https://github.com/raymayemir">
<img src="https://avatars2.githubusercontent.com/u/5638101?s=460&v=4" width="100px"></br>
<sub><b>Ray Mayemir</b></sub>
</a>
</td>
<td align="center">
<a href="https://github.com/melkorm">
<img src="https://avatars2.githubusercontent.com/u/619996?s=460&v=4" width="100px"></br>
<sub><b>melkorm</b></sub>
</a>
</td>
<td align="center">
<a href="https://github.com/ekaputra07">
<img src="https://avatars3.githubusercontent.com/u/1094221?s=460&v=4" width="100px"></br>
<sub><b>Eka Putra</b></sub>
</a>
</td>
<td align="center">
<a href="https://github.com/bihe">
<img src="https://avatars1.githubusercontent.com/u/635852?s=460&v=4" width="100px"></br>
<sub><b>HenrikBinggl</b></sub>
<sub><b>Henrik Binggl</b></sub>
</a>
</td>
<td align="center">

24
.github/README_tr.md vendored
View File

@ -156,8 +156,8 @@ func main() {
})
// GET /api/register
app.Get("/api*", func(c *fiber.Ctx) {
fmt.Printf("/api%s", c.Params("*"))
app.Get("/api/*", func(c *fiber.Ctx) {
fmt.Printf("/api/%s", c.Params("*"))
// => /api/register
})
@ -487,10 +487,28 @@ Eğer **teşekkür etmek** ve/veya `Fiber` ın aktif geliştirilmesini destekle
<table>
<tr>
<td align="center">
<a href="https://github.com/raymayemir">
<img src="https://avatars2.githubusercontent.com/u/5638101?s=460&v=4" width="100px"></br>
<sub><b>Ray Mayemir</b></sub>
</a>
</td>
<td align="center">
<a href="https://github.com/melkorm">
<img src="https://avatars2.githubusercontent.com/u/619996?s=460&v=4" width="100px"></br>
<sub><b>melkorm</b></sub>
</a>
</td>
<td align="center">
<a href="https://github.com/ekaputra07">
<img src="https://avatars3.githubusercontent.com/u/1094221?s=460&v=4" width="100px"></br>
<sub><b>Eka Putra</b></sub>
</a>
</td>
<td align="center">
<a href="https://github.com/bihe">
<img src="https://avatars1.githubusercontent.com/u/635852?s=460&v=4" width="100px"></br>
<sub><b>HenrikBinggl</b></sub>
<sub><b>Henrik Binggl</b></sub>
</a>
</td>
<td align="center">

View File

@ -156,8 +156,8 @@ func main() {
})
// GET /api/register
app.Get("/api*", func(c *fiber.Ctx) {
fmt.Printf("/api%s", c.Params("*"))
app.Get("/api/*", func(c *fiber.Ctx) {
fmt.Printf("/api/%s", c.Params("*"))
// => /api/register
})
@ -487,10 +487,28 @@ func main() {
<table>
<tr>
<td align="center">
<a href="https://github.com/raymayemir">
<img src="https://avatars2.githubusercontent.com/u/5638101?s=460&v=4" width="100px"></br>
<sub><b>Ray Mayemir</b></sub>
</a>
</td>
<td align="center">
<a href="https://github.com/melkorm">
<img src="https://avatars2.githubusercontent.com/u/619996?s=460&v=4" width="100px"></br>
<sub><b>melkorm</b></sub>
</a>
</td>
<td align="center">
<a href="https://github.com/ekaputra07">
<img src="https://avatars3.githubusercontent.com/u/1094221?s=460&v=4" width="100px"></br>
<sub><b>Eka Putra</b></sub>
</a>
</td>
<td align="center">
<a href="https://github.com/bihe">
<img src="https://avatars1.githubusercontent.com/u/635852?s=460&v=4" width="100px"></br>
<sub><b>HenrikBinggl</b></sub>
<sub><b>Henrik Binggl</b></sub>
</a>
</td>
<td align="center">

View File

@ -23,4 +23,3 @@ script:
- GOARCH=386 go build
- go test -v
- go test -race -v

48
app.go
View File

@ -24,7 +24,7 @@ import (
)
// Version of current package
const Version = "1.8.43"
const Version = "1.9.0"
// Map is a shortcut for map[string]interface{}
type Map map[string]interface{}
@ -70,32 +70,23 @@ type Group struct {
app *App
}
// Global variables
var isPrefork, isChild bool
// New creates a new Fiber named instance.
// You can pass optional settings when creating a new instance.
func New(settings ...*Settings) *App {
// Parse arguments
for _, v := range os.Args[1:] {
if v == "-prefork" {
isPrefork = true
} else if v == "-child" {
isChild = true
}
}
schemaDecoderForm.SetAliasTag("form")
schemaDecoderQuery.SetAliasTag("query")
// Create app
app := new(App)
// Create settings
app.Settings = new(Settings)
// Set default settings
app.Settings.Prefork = isPrefork
app.Settings.Prefork = isPrefork()
app.Settings.BodyLimit = 4 * 1024 * 1024
// If settings exist, set defaults
if len(settings) > 0 {
app.Settings = settings[0] // Set custom settings
if !app.Settings.Prefork { // Default to -prefork flag if false
app.Settings.Prefork = isPrefork
app.Settings.Prefork = isPrefork()
}
if app.Settings.BodyLimit == 0 { // Default MaxRequestBodySize
app.Settings.BodyLimit = 4 * 1024 * 1024
@ -323,6 +314,25 @@ func (grp *Group) All(path string, handlers ...func(*Ctx)) *Group {
return grp
}
// Serve can be used to pass a custom listener
// This method does not support the Prefork feature
// You can pass an optional *tls.Config to enable TLS.
func (app *App) Serve(ln net.Listener, tlsconfig ...*tls.Config) error {
// Create fasthttp server
app.server = app.newServer()
// TLS config
if len(tlsconfig) > 0 {
ln = tls.NewListener(ln, tlsconfig[0])
}
// Preforkin is not available using app.Serve(ln net.Listener)
if app.Settings.Prefork {
fmt.Println("Preforking is not available with 'Serve' please use 'Listen' to enable it.")
}
// Print listening message
fmt.Printf("Fiber v%s listening on %s\n", Version, ln.Addr().String())
return app.server.Serve(ln)
}
// Listen serves HTTP requests from the given addr or port.
// You can pass an optional *tls.Config to enable TLS.
func (app *App) Listen(address interface{}, tlsconfig ...*tls.Config) error {
@ -343,7 +353,7 @@ func (app *App) Listen(address interface{}, tlsconfig ...*tls.Config) error {
var ln net.Listener
var err error
// Prefork enabled
if app.Settings.Prefork && runtime.NumCPU() > 1 {
if app.Settings.Prefork && runtime.NumCPU() > 1 && runtime.GOOS != "windows" {
if ln, err = app.prefork(addr); err != nil {
return err
}
@ -352,14 +362,12 @@ func (app *App) Listen(address interface{}, tlsconfig ...*tls.Config) error {
return err
}
}
// TLS config
if len(tlsconfig) > 0 {
ln = tls.NewListener(ln, tlsconfig[0])
}
// Print listening message
if !isChild {
if !isChild() {
fmt.Printf("Fiber v%s listening on %s\n", Version, addr)
}
return app.server.Serve(ln)
@ -379,7 +387,7 @@ func (app *App) Shutdown() error {
return app.server.Shutdown()
}
// Test is used for internal debugging by passing a *http.Request.
// Test is used for internal debugging by passing a *http.Request
// Timeout is optional and defaults to 200ms, -1 will disable it completely.
func (app *App) Test(request *http.Request, msTimeout ...int) (*http.Response, error) {
timeout := 200
@ -430,7 +438,7 @@ func (app *App) Test(request *http.Request, msTimeout ...int) (*http.Response, e
// Sharding: https://www.nginx.com/blog/socket-sharding-nginx-release-1-9-1/
func (app *App) prefork(address string) (ln net.Listener, err error) {
// Master proc
if !isChild {
if !isChild() {
addr, err := net.ResolveTCPAddr("tcp", address)
if err != nil {
return ln, err

View File

@ -2,11 +2,17 @@
// 📌 API Documentation: https://fiber.wiki
// 📝 Github Repository: https://github.com/gofiber/fiber
// go test -v -coverprofile cover.out .
// go tool cover -html=cover.out -o cover.html
// open cover.html
package fiber
import (
"net"
"net/http"
"testing"
"time"
)
var handler = func(c *Ctx) {}
@ -67,6 +73,20 @@ func Test_Methods(t *testing.T) {
}
func Test_New(t *testing.T) {
app := New(&Settings{
Immutable: true,
})
app.Get("/", func(*Ctx) {
})
}
func Test_Shutdown(t *testing.T) {
app := New()
_ = app.Shutdown()
}
func Test_Static(t *testing.T) {
app := New()
grp := app.Group("/v1")
@ -167,18 +187,31 @@ func Test_Group(t *testing.T) {
is200(t, app, "/test/v1/users", "GET")
}
// func Test_Listen(t *testing.T) {
// t.Parallel()
// app := New()
// app.Banner = false
// go func() {
// time.Sleep(1 * time.Second)
// _ = app.Shutdown()
// }()
// app.Listen(3002)
// go func() {
// time.Sleep(1 * time.Second)
// _ = app.Shutdown()
// }()
// app.Listen("3002")
// }
func Test_Listen(t *testing.T) {
app := New()
go func() {
time.Sleep(500 * time.Millisecond)
_ = app.Shutdown()
}()
app.Listen(3002)
go func() {
time.Sleep(500 * time.Millisecond)
_ = app.Shutdown()
}()
app.Listen("3003")
}
func Test_Serve(t *testing.T) {
app := New(&Settings{
Prefork: true,
})
ln, err := net.Listen("tcp4", ":3004")
if err != nil {
t.Fatalf(`%s: %s`, t.Name(), err)
}
go func() {
time.Sleep(500 * time.Millisecond)
_ = app.Shutdown()
}()
app.Serve(ln)
}

19
ctx.go
View File

@ -61,7 +61,8 @@ type Cookie struct {
// Global variables
var jsonParser = jsoniter.ConfigCompatibleWithStandardLibrary
var schemaDecoder = schema.NewDecoder()
var schemaDecoderForm = schema.NewDecoder()
var schemaDecoderQuery = schema.NewDecoder()
// Ctx pool
var poolCtx = sync.Pool{
@ -256,7 +257,7 @@ func (ctx *Ctx) Body(key ...string) string {
// It supports decoding the following content types based on the Content-Type header:
// application/json, application/xml, application/x-www-form-urlencoded, multipart/form-data
func (ctx *Ctx) BodyParser(out interface{}) error {
// TODO : Query Params
// get content type
ctype := getString(ctx.Fasthttp.Request.Header.ContentType())
// application/json
if strings.HasPrefix(ctype, MIMEApplicationJSON) {
@ -272,7 +273,7 @@ func (ctx *Ctx) BodyParser(out interface{}) error {
if err != nil {
return err
}
return schemaDecoder.Decode(out, data)
return schemaDecoderForm.Decode(out, data)
}
// multipart/form-data
if strings.HasPrefix(ctype, MIMEMultipartForm) {
@ -280,9 +281,17 @@ func (ctx *Ctx) BodyParser(out interface{}) error {
if err != nil {
return err
}
return schemaDecoder.Decode(out, data.Value)
return schemaDecoderForm.Decode(out, data.Value)
}
// query Params
if ctx.Fasthttp.QueryArgs().Len() > 0 {
data := make(map[string][]string)
ctx.Fasthttp.QueryArgs().VisitAll(func(key []byte, val []byte) {
data[getString(key)] = []string{getString(val)}
})
return schemaDecoderQuery.Decode(out, data)
}
return fmt.Errorf("BodyParser: cannot parse content-type: %v", ctype)
}

View File

@ -156,11 +156,11 @@ func Test_Body(t *testing.T) {
func Test_BodyParser(t *testing.T) {
app := New()
type Demo struct {
Name string `json:"name"`
Name string `json:"name" xml:"name" form:"name" query:"name"`
}
app.Post("/test", func(c *Ctx) {
d := new(Demo)
err := c.BodyParser(&d)
err := c.BodyParser(d)
if err != nil {
t.Fatalf(`%s: BodyParser %v`, t.Name(), err)
}
@ -176,6 +176,26 @@ func Test_BodyParser(t *testing.T) {
if err != nil {
t.Fatalf(`%s: %s`, t.Name(), err)
}
// data := url.Values{}
// data.Set("name", "john")
// req = httptest.NewRequest("POST", "/test", strings.NewReader(data.Encode()))
// req.Header.Add("Content-Type", "application/x-www-form-urlencoded")
// req.Header.Add("Content-Length", strconv.Itoa(len(data.Encode())))
// _, err = app.Test(req)
// if err != nil {
// t.Fatalf(`%s: %s`, t.Name(), err)
// }
// req = httptest.NewRequest("POST", "/test", bytes.NewBuffer([]byte(`<name>john</name>`)))
// req.Header.Set("Content-Type", "application/xml")
// req.Header.Set("Content-Length", strconv.Itoa(len([]byte(`<name>john</name>`))))
// _, err = app.Test(req)
// if err != nil {
// t.Fatalf(`%s: %s`, t.Name(), err)
// }
}
func Test_Cookies(t *testing.T) {
app := New()

7
go.sum
View File

@ -7,12 +7,19 @@ github.com/json-iterator/go v1.1.9 h1:9yzud/Ht36ygwatGx56VwCZtlI/2AD15T1X2sjSuGn
github.com/json-iterator/go v1.1.9/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4=
github.com/klauspost/compress v1.8.2 h1:Bx0qjetmNjdFXASH02NSAREKpiaDwkO1DRZ3dV2KCcs=
github.com/klauspost/compress v1.8.2/go.mod h1:RyIbtBH6LamlWaDj8nUwkbUhJ87Yi3uG0guNDohfE1A=
github.com/klauspost/compress v1.10.4 h1:jFzIFaf586tquEB5EhzQG0HwGNSlgAJpG53G6Ss11wc=
github.com/klauspost/compress v1.10.4/go.mod h1:aoV0uJVorq1K+umq18yTdKaF57EivdYsUV+/s2qKfXs=
github.com/klauspost/cpuid v1.2.1 h1:vJi+O/nMdFt0vqm8NZBI6wzALWdA2X+egi0ogNyrC/w=
github.com/klauspost/cpuid v1.2.1/go.mod h1:Pj4uuM528wm8OyEC2QMXAi2YiTZ96dNQPGgoMS4s3ek=
github.com/klauspost/cpuid v1.2.3/go.mod h1:Pj4uuM528wm8OyEC2QMXAi2YiTZ96dNQPGgoMS4s3ek=
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421 h1:ZqeYNhU3OHLH3mGKHDcjJRFFRrJa6eAM5H+CtDdOsPc=
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg=
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742 h1:Esafd1046DLDQ0W1YjYsBW+p8U2u7vzgW2SQVmlNazg=
github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
github.com/modern-go/reflect2 v1.0.1 h1:9f412s+6RmYXLWZSEzVVgPGK7C2PphHj5RJrvfx9AWI=
github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=

View File

@ -115,6 +115,26 @@ var getBytesImmutable = func(s string) (b []byte) {
return []byte(s)
}
// Check if -prefork is in arguments
func isPrefork() bool {
for _, v := range os.Args[1:] {
if v == "-prefork" {
return true
}
}
return false
}
// Check if -child is in arguments
func isChild() bool {
for _, v := range os.Args[1:] {
if v == "-child" {
return true
}
}
return false
}
// https://golang.org/src/net/net.go#L113
// Helper methods for application#test
type testConn struct {