diff --git a/README.md b/README.md
index 7491baa3..429678c7 100644
--- a/README.md
+++ b/README.md
@@ -30,14 +30,15 @@
-iris is a web application framework written in Go.
-Easy to learn, while it's highly customizable.
+Iris is a well known web application framework written in Go.
+
+Easy to learn, while it's highly customizable,
+ideally suited for both experienced and novice Developers.
Its only sin?
To be the fastest web framework was ever published under open-source circumstances.
-Companies' offers were rejected, free forever.
-Enjoy this framework now, without hesitation.
+Enjoy yourself!
@@ -45,22 +46,17 @@ To be the fastest web framework was ever published under open-source circ
Quick Start
-----------
-The only requirement is the [Go Programming Language](https://golang.org/dl), at least v1.7.
+The only requirement is the [Go Programming Language](https://golang.org/dl) 1.7+
```bash
-$ go get -u github.com/kataras/iris
+$ go get -u github.com/kataras/iris/iris
```
-> Production? Install the [stable version](https://github.com/kataras/iris/tree/4.0.0#versioning) instead
-```bash
-$ go get -u gopkg.in/kataras/iris.v4
-```
-
-### Hello, World!
+### Hello, JSON!
```sh
-$ cat helloworld.go
+$ cat hellojson.go
```
```go
@@ -70,21 +66,37 @@ import "github.com/kataras/iris"
func main(){
- iris.Get("/", func(c *iris.Context){
- c.HTML(iris.StatusOK, " Hello World!
")
+ // http://localhost:5700/api/user/42
+ // Method: "GET"
+ iris.Get("/api/user/:id", func(ctx *iris.Context){
+
+ // take the :id from the path, parse to integer
+ // and set it to the new userID local variable.
+ userID := ctx.ParamInt("id")
+
+ // userRepo, imaginary database service <- your only job.
+ user := userRepo.GetByID(userID)
+
+ // send back a response to the client,
+ // .JSON: content type as application/json; charset="utf-8"
+ // iris.StatusOK: with 200 http status code.
+ //
+ // send user as it is or make use of any json valid golang type,
+ // like the iris.Map{"username" : user.Username}.
+ ctx.JSON(iris.StatusOK, user)
+
})
-
- iris.Listen(":8080")
+ iris.Listen("localhost:5700")
}
```
```sh
-$ go run helloworld.go
+$ go run hellojson.go
```
-Open your browser at http://localhost:8080 and you should see the `Hello World!`.
+Open your browser or any other http client at http://localhost:5700/api/user/42.
### New
diff --git a/context.go b/context.go
index ec381e59..abbdbd72 100644
--- a/context.go
+++ b/context.go
@@ -471,6 +471,10 @@ func (ctx *Context) SetHeader(k string, v string) {
ctx.RequestCtx.Response.Header.Set(k, v)
}
+// it used only inside Redirect,
+// keep it here for allocations reason
+var httpsSchemeOnlyBytes = []byte("https")
+
// Redirect redirect sends a redirect response the client
// accepts 2 parameters string and an optional int
// first parameter is the url to redirect
@@ -486,12 +490,10 @@ func (ctx *Context) Redirect(urlToRedirect string, statusHeader ...int) {
// #355
if ctx.IsTLS() {
- u := fasthttp.AcquireURI()
- ctx.URI().CopyTo(u)
- u.SetScheme("https")
+ u := ctx.URI()
+ u.SetSchemeBytes(httpsSchemeOnlyBytes)
u.Update(urlToRedirect)
ctx.SetHeader("Location", string(u.FullURI()))
- fasthttp.ReleaseURI(u)
ctx.SetStatusCode(httpStatus)
return
}
diff --git a/http_test.go b/http_test.go
index 97586e11..1329fe4d 100644
--- a/http_test.go
+++ b/http_test.go
@@ -751,3 +751,50 @@ func TestCache(t *testing.T) {
t.Fatal(err)
}
}
+
+func TestRedirectHTTPS(t *testing.T) {
+ host := "localhost:5700"
+ expectedBody := "Redirected to https://" + host + "/redirected"
+ iris.ResetDefault()
+ defer iris.Close()
+
+ iris.Set(iris.OptionDisableBanner(true))
+
+ iris.Get("/redirect", func(ctx *iris.Context) { ctx.Redirect("/redirected") })
+ iris.Get("/redirected", func(ctx *iris.Context) { ctx.Text(iris.StatusOK, "Redirected to "+ctx.URI().String()) })
+
+ // create the key and cert files on the fly, and delete them when this test finished
+ // note: code dublication but it's ok we may change that to local ListenLETSENCRYPT
+ certFile, ferr := ioutil.TempFile("", "cert")
+
+ if ferr != nil {
+ t.Fatal(ferr.Error())
+ }
+
+ keyFile, ferr := ioutil.TempFile("", "key")
+ if ferr != nil {
+ t.Fatal(ferr.Error())
+ }
+
+ defer func() {
+ certFile.Close()
+ time.Sleep(350 * time.Millisecond)
+ os.Remove(certFile.Name())
+
+ keyFile.Close()
+ time.Sleep(350 * time.Millisecond)
+ os.Remove(keyFile.Name())
+ }()
+
+ certFile.WriteString(testTLSCert)
+ keyFile.WriteString(testTLSKey)
+
+ go iris.ListenTLS(host, certFile.Name(), keyFile.Name())
+ if ok := <-iris.Default.Available; !ok {
+ t.Fatal("Unexpected error: server cannot start, please report this as bug!!")
+ }
+
+ e := httptest.New(iris.Default, t, httptest.ExplicitURL(true))
+
+ e.Request("GET", "https://"+host+"/redirect").Expect().Status(iris.StatusOK).Body().Equal(expectedBody)
+}