File tree 3 files changed +65
-24
lines changed 3 files changed +65
-24
lines changed Original file line number Diff line number Diff line change 5
5
package cmd
6
6
7
7
import (
8
- "crypto/tls"
9
8
"fmt"
10
9
"net"
11
10
"net/http"
@@ -31,7 +30,6 @@ import (
31
30
"code.gitea.io/gitea/routers/repo"
32
31
"code.gitea.io/gitea/routers/user"
33
32
34
- "github.com/facebookgo/grace/gracehttp"
35
33
"github.com/go-macaron/binding"
36
34
"github.com/go-macaron/cache"
37
35
"github.com/go-macaron/captcha"
@@ -616,29 +614,9 @@ func runWeb(ctx *cli.Context) error {
616
614
var err error
617
615
switch setting .Protocol {
618
616
case setting .HTTP :
619
- err = gracehttp .Serve (& http.Server {
620
- Addr : listenAddr ,
621
- Handler : m ,
622
- })
617
+ err = runHTTP (listenAddr , m )
623
618
case setting .HTTPS :
624
- config := & tls.Config {
625
- MinVersion : tls .VersionTLS10 ,
626
- }
627
- if config .NextProtos == nil {
628
- config .NextProtos = []string {"http/1.1" }
629
- }
630
-
631
- config .Certificates = make ([]tls.Certificate , 1 )
632
- config .Certificates [0 ], err = tls .LoadX509KeyPair (setting .CertFile , setting .KeyFile )
633
- if err != nil {
634
- log .Fatal (4 , "Failed to load https cert file %s: %v" , listenAddr , err )
635
- }
636
-
637
- err = gracehttp .Serve (& http.Server {
638
- Addr : listenAddr ,
639
- Handler : m ,
640
- TLSConfig : config ,
641
- })
619
+ err = runHTTPS (listenAddr , setting .CertFile , setting .KeyFile , m )
642
620
case setting .FCGI :
643
621
err = fcgi .Serve (nil , m )
644
622
case setting .UnixSocket :
Original file line number Diff line number Diff line change
1
+ // +build !windows
2
+
3
+ // Copyright 2016 The Gitea Authors. All rights reserved.
4
+ // Use of this source code is governed by a MIT-style
5
+ // license that can be found in the LICENSE file.
6
+
7
+ package cmd
8
+
9
+ import (
10
+ "crypto/tls"
11
+ "log"
12
+ "net/http"
13
+
14
+ "github.com/facebookgo/grace/gracehttp"
15
+ )
16
+
17
+ func runHTTP (listenAddr string , m http.Handler ) error {
18
+ return gracehttp .Serve (& http.Server {
19
+ Addr : listenAddr ,
20
+ Handler : m ,
21
+ })
22
+ }
23
+
24
+ func runHTTPS (listenAddr , certFile , keyFile string , m http.Handler ) error {
25
+ config := & tls.Config {
26
+ MinVersion : tls .VersionTLS10 ,
27
+ }
28
+ if config .NextProtos == nil {
29
+ config .NextProtos = []string {"http/1.1" }
30
+ }
31
+
32
+ config .Certificates = make ([]tls.Certificate , 1 )
33
+ var err error
34
+ config .Certificates [0 ], err = tls .LoadX509KeyPair (certFile , keyFile )
35
+ if err != nil {
36
+ log .Fatal (4 , "Failed to load https cert file %s: %v" , listenAddr , err )
37
+ }
38
+
39
+ return gracehttp .Serve (& http.Server {
40
+ Addr : listenAddr ,
41
+ Handler : m ,
42
+ TLSConfig : config ,
43
+ })
44
+ }
Original file line number Diff line number Diff line change
1
+ // +build windows
2
+
3
+ // Copyright 2016 The Gitea Authors. All rights reserved.
4
+ // Use of this source code is governed by a MIT-style
5
+ // license that can be found in the LICENSE file.
6
+
7
+ package cmd
8
+
9
+ import (
10
+ "net/http"
11
+ )
12
+
13
+ func runHTTP (listenAddr string , m http.Handler ) error {
14
+ return http .ListenAndServe (listenAddr , m )
15
+ }
16
+
17
+ func runHTTPS (listenAddr , certFile , keyFile string , m http.Handler ) error {
18
+ return http .ListenAndServeTLS (listenAddr , certFile , keyFile , m )
19
+ }
You can’t perform that action at this time.
0 commit comments