mirror of
https://github.com/gofiber/fiber.git
synced 2025-02-19 13:27:53 +00:00
commit
a2f2e76c3d
28
.github/TEST_DATA/ssl.key
vendored
Normal file
28
.github/TEST_DATA/ssl.key
vendored
Normal file
@ -0,0 +1,28 @@
|
||||
-----BEGIN PRIVATE KEY-----
|
||||
MIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQD4IQusAs8PJdnG
|
||||
3mURt/AXtgC+ceqLOatJ49JJE1VPTkMAy+oE1f1XvkMrYsHqmDf6GWVzgVXryL4U
|
||||
wq2/nJSm56ddhN55nI8oSN3dtywUB8/ShelEN73nlN77PeD9tl6NksPwWaKrqxq0
|
||||
FlabRPZSQCfmgZbhDV8Sa8mfCkFU0G0lit6kLGceCKMvmW+9Bz7ebsYmVdmVMxmf
|
||||
IJStFD44lWFTdUc65WISKEdW2ELcUefb0zOLw+0PCbXFGJH5x5ktksW8+BBk2Hkg
|
||||
GeQRL/qPCccthbScO0VgNj3zJ3ZZL0ObSDAbvNDG85joeNjDNq5DT/BAZ0bOSbEF
|
||||
sh+f9BAzAgMBAAECggEBAJWv2cq7Jw6MVwSRxYca38xuD6TUNBopgBvjREixURW2
|
||||
sNUaLuMb9Omp7fuOaE2N5rcJ+xnjPGIxh/oeN5MQctz9gwn3zf6vY+15h97pUb4D
|
||||
uGvYPRDaT8YVGS+X9NMZ4ZCmqW2lpWzKnCFoGHcy8yZLbcaxBsRdvKzwOYGoPiFb
|
||||
K2QuhXZ/1UPmqK9i2DFKtj40X6vBszTNboFxOVpXrPu0FJwLVSDf2hSZ4fMM0DH3
|
||||
YqwKcYf5te+hxGKgrqRA3tn0NCWii0in6QIwXMC+kMw1ebg/tZKqyDLMNptAK8J+
|
||||
DVw9m5X1seUHS5ehU/g2jrQrtK5WYn7MrFK4lBzlRwECgYEA/d1TeANYECDWRRDk
|
||||
B0aaRZs87Rwl/J9PsvbsKvtU/bX+OfSOUjOa9iQBqn0LmU8GqusEET/QVUfocVwV
|
||||
Bggf/5qDLxz100Rj0ags/yE/kNr0Bb31kkkKHFMnCT06YasR7qKllwrAlPJvQv9x
|
||||
IzBKq+T/Dx08Wep9bCRSFhzRCnsCgYEA+jdeZXTDr/Vz+D2B3nAw1frqYFfGnEVY
|
||||
wqmoK3VXMDkGuxsloO2rN+SyiUo3JNiQNPDub/t7175GH5pmKtZOlftePANsUjBj
|
||||
wZ1D0rI5Bxu/71ibIUYIRVmXsTEQkh/ozoh3jXCZ9+bLgYiYx7789IUZZSokFQ3D
|
||||
FICUT9KJ36kCgYAGoq9Y1rWJjmIrYfqj2guUQC+CfxbbGIrrwZqAsRsSmpwvhZ3m
|
||||
tiSZxG0quKQB+NfSxdvQW5ulbwC7Xc3K35F+i9pb8+TVBdeaFkw+yu6vaZmxQLrX
|
||||
fQM/pEjD7A7HmMIaO7QaU5SfEAsqdCTP56Y8AftMuNXn/8IRfo2KuGwaWwKBgFpU
|
||||
ILzJoVdlad9E/Rw7LjYhZfkv1uBVXIyxyKcfrkEXZSmozDXDdxsvcZCEfVHM6Ipk
|
||||
K/+7LuMcqp4AFEAEq8wTOdq6daFaHLkpt/FZK6M4TlruhtpFOPkoNc3e45eM83OT
|
||||
6mziKINJC1CQ6m65sQHpBtjxlKMRG8rL/D6wx9s5AoGBAMRlqNPMwglT3hvDmsAt
|
||||
9Lf9pdmhERUlHhD8bj8mDaBj2Aqv7f6VRJaYZqP403pKKQexuqcn80mtjkSAPFkN
|
||||
Cj7BVt/RXm5uoxDTnfi26RF9F6yNDEJ7UU9+peBr99aazF/fTgW/1GcMkQnum8uV
|
||||
c257YgaWmjK9uB0Y2r2VxS0G
|
||||
-----END PRIVATE KEY-----
|
17
.github/TEST_DATA/ssl.pem
vendored
Normal file
17
.github/TEST_DATA/ssl.pem
vendored
Normal file
@ -0,0 +1,17 @@
|
||||
-----BEGIN CERTIFICATE-----
|
||||
MIICujCCAaKgAwIBAgIJAMbXnKZ/cikUMA0GCSqGSIb3DQEBCwUAMBUxEzARBgNV
|
||||
BAMTCnVidW50dS5uYW4wHhcNMTUwMjA0MDgwMTM5WhcNMjUwMjAxMDgwMTM5WjAV
|
||||
MRMwEQYDVQQDEwp1YnVudHUubmFuMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIB
|
||||
CgKCAQEA+CELrALPDyXZxt5lEbfwF7YAvnHqizmrSePSSRNVT05DAMvqBNX9V75D
|
||||
K2LB6pg3+hllc4FV68i+FMKtv5yUpuenXYTeeZyPKEjd3bcsFAfP0oXpRDe955Te
|
||||
+z3g/bZejZLD8Fmiq6satBZWm0T2UkAn5oGW4Q1fEmvJnwpBVNBtJYrepCxnHgij
|
||||
L5lvvQc+3m7GJlXZlTMZnyCUrRQ+OJVhU3VHOuViEihHVthC3FHn29Mzi8PtDwm1
|
||||
xRiR+ceZLZLFvPgQZNh5IBnkES/6jwnHLYW0nDtFYDY98yd2WS9Dm0gwG7zQxvOY
|
||||
6HjYwzauQ0/wQGdGzkmxBbIfn/QQMwIDAQABow0wCzAJBgNVHRMEAjAAMA0GCSqG
|
||||
SIb3DQEBCwUAA4IBAQBQjKm/4KN/iTgXbLTL3i7zaxYXFLXsnT1tF+ay4VA8aj98
|
||||
L3JwRTciZ3A5iy/W4VSCt3eASwOaPWHKqDBB5RTtL73LoAqsWmO3APOGQAbixcQ2
|
||||
45GXi05OKeyiYRi1Nvq7Unv9jUkRDHUYVPZVSAjCpsXzPhFkmZoTRxmx5l0ZF7Li
|
||||
K91lI5h+eFq0dwZwrmlPambyh1vQUi70VHv8DNToVU29kel7YLbxGbuqETfhrcy6
|
||||
X+Mha6RYITkAn5FqsZcKMsc9eYGEF4l3XV+oS7q6xfTxktYJMFTI18J0lQ2Lv/CI
|
||||
whdMnYGntDQBE/iFCrJEGNsKGc38796GBOb5j+zd
|
||||
-----END CERTIFICATE-----
|
2
app.go
2
app.go
@ -33,7 +33,7 @@ import (
|
||||
)
|
||||
|
||||
// Version of current package
|
||||
const Version = "1.12.7"
|
||||
const Version = "1.13.0"
|
||||
|
||||
// Map is a shortcut for map[string]interface{}, useful for JSON returns
|
||||
type Map map[string]interface{}
|
||||
|
40
app_test.go
40
app_test.go
@ -5,9 +5,11 @@
|
||||
package fiber
|
||||
|
||||
import (
|
||||
"crypto/tls"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"net"
|
||||
"net/http/httptest"
|
||||
"reflect"
|
||||
"regexp"
|
||||
@ -249,6 +251,44 @@ func Test_App_Add_Method_Test(t *testing.T) {
|
||||
})
|
||||
}
|
||||
|
||||
func Test_App_Listen_TLS(t *testing.T) {
|
||||
app := New()
|
||||
|
||||
// Create tls certificate
|
||||
cer, err := tls.LoadX509KeyPair("./.github/TEST_DATA/ssl.pem", "./.github/TEST_DATA/ssl.key")
|
||||
if err != nil {
|
||||
utils.AssertEqual(t, nil, err)
|
||||
}
|
||||
config := &tls.Config{Certificates: []tls.Certificate{cer}}
|
||||
|
||||
go func() {
|
||||
time.Sleep(1000 * time.Millisecond)
|
||||
utils.AssertEqual(t, nil, app.Shutdown())
|
||||
}()
|
||||
|
||||
utils.AssertEqual(t, nil, app.Listen(3078, config))
|
||||
}
|
||||
|
||||
func Test_App_Listener_TLS(t *testing.T) {
|
||||
app := New()
|
||||
|
||||
// Create tls certificate
|
||||
cer, err := tls.LoadX509KeyPair("./.github/TEST_DATA/ssl.pem", "./.github/TEST_DATA/ssl.key")
|
||||
if err != nil {
|
||||
utils.AssertEqual(t, nil, err)
|
||||
}
|
||||
config := &tls.Config{Certificates: []tls.Certificate{cer}}
|
||||
|
||||
go func() {
|
||||
time.Sleep(1000 * time.Millisecond)
|
||||
utils.AssertEqual(t, nil, app.Shutdown())
|
||||
}()
|
||||
|
||||
ln, err := net.Listen("tcp4", ":3055")
|
||||
utils.AssertEqual(t, nil, err)
|
||||
|
||||
utils.AssertEqual(t, nil, app.Listener(ln, config))
|
||||
}
|
||||
func Test_App_Use_Params_Group(t *testing.T) {
|
||||
app := New()
|
||||
|
||||
|
3
ctx.go
3
ctx.go
@ -355,9 +355,6 @@ func (ctx *Ctx) Download(file string, filename ...string) error {
|
||||
|
||||
// Error contains the error information passed via the Next(err) method.
|
||||
func (ctx *Ctx) Error() error {
|
||||
if ctx.err == nil {
|
||||
return errors.New("")
|
||||
}
|
||||
return ctx.err
|
||||
}
|
||||
|
||||
|
29
ctx_test.go
29
ctx_test.go
@ -898,7 +898,11 @@ func Test_Ctx_Path(t *testing.T) {
|
||||
// go test -run Test_Ctx_Protocol
|
||||
func Test_Ctx_Protocol(t *testing.T) {
|
||||
app := New()
|
||||
ctx := app.AcquireCtx(&fasthttp.RequestCtx{})
|
||||
|
||||
freq := &fasthttp.RequestCtx{}
|
||||
freq.Request.Header.Set("X-Forwarded", "invalid")
|
||||
|
||||
ctx := app.AcquireCtx(freq)
|
||||
defer app.ReleaseCtx(ctx)
|
||||
ctx.Fasthttp.Request.Header.Set(HeaderXForwardedProto, "https")
|
||||
utils.AssertEqual(t, "https", ctx.Protocol())
|
||||
@ -1144,7 +1148,7 @@ func Test_Ctx_Download(t *testing.T) {
|
||||
|
||||
// go test -race -run Test_Ctx_SendFile
|
||||
func Test_Ctx_SendFile(t *testing.T) {
|
||||
//t.Parallel()
|
||||
t.Parallel()
|
||||
app := New()
|
||||
|
||||
// fetch file content
|
||||
@ -1184,6 +1188,13 @@ func Test_Ctx_SendFile(t *testing.T) {
|
||||
utils.AssertEqual(t, StatusNotModified, ctx.Fasthttp.Response.StatusCode())
|
||||
utils.AssertEqual(t, []byte(nil), ctx.Fasthttp.Response.Body())
|
||||
app.ReleaseCtx(ctx)
|
||||
|
||||
// test 404
|
||||
// ctx = app.AcquireCtx(&fasthttp.RequestCtx{})
|
||||
// err = ctx.SendFile("./john_doe.go")
|
||||
// // check expectation
|
||||
// utils.AssertEqual(t, StatusNotFound, ctx.Fasthttp.Response.StatusCode())
|
||||
// app.ReleaseCtx(ctx)
|
||||
}
|
||||
|
||||
// go test -race -run Test_Ctx_SendFile_Immutable
|
||||
@ -1400,7 +1411,7 @@ func Test_Ctx_Render(t *testing.T) {
|
||||
app := New()
|
||||
ctx := app.AcquireCtx(&fasthttp.RequestCtx{})
|
||||
defer app.ReleaseCtx(ctx)
|
||||
err := ctx.Render("./.github/template.html", Map{
|
||||
err := ctx.Render("./.github/TEST_DATA/template.html", Map{
|
||||
"Title": "Hello, World!",
|
||||
})
|
||||
utils.AssertEqual(t, nil, err)
|
||||
@ -1417,7 +1428,7 @@ func (t *testTemplateEngine) Render(w io.Writer, name string, bind interface{},
|
||||
}
|
||||
|
||||
func (t *testTemplateEngine) Load() error {
|
||||
t.templates = template.Must(template.ParseGlob("./.github/*.tmpl"))
|
||||
t.templates = template.Must(template.ParseGlob("./.github/TEST_DATA/*.tmpl"))
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -1786,3 +1797,13 @@ func Benchmark_Ctx_QueryParser(b *testing.B) {
|
||||
}
|
||||
utils.AssertEqual(b, nil, ctx.QueryParser(q))
|
||||
}
|
||||
|
||||
// go test -run Test_Ctx_Error
|
||||
func Test_Ctx_Error(t *testing.T) {
|
||||
t.Parallel()
|
||||
app := New()
|
||||
ctx := app.AcquireCtx(&fasthttp.RequestCtx{})
|
||||
defer app.ReleaseCtx(ctx)
|
||||
ctx.Next(fmt.Errorf("Hi I'm an error!"))
|
||||
utils.AssertEqual(t, "Hi I'm an error!", ctx.Error().Error())
|
||||
}
|
||||
|
@ -20,7 +20,7 @@ import (
|
||||
var routesFixture = routeJSON{}
|
||||
|
||||
func init() {
|
||||
dat, err := ioutil.ReadFile("./.github/fixture/testRoutes.json")
|
||||
dat, err := ioutil.ReadFile("./.github/TEST_DATA/testRoutes.json")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user