Skip to content

Commit 2c881d8

Browse files
committed
Add template for other browsers than firefox
1 parent 37c1917 commit 2c881d8

File tree

2 files changed

+21
-5
lines changed

2 files changed

+21
-5
lines changed

certificates.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,11 @@ import (
2121
"net"
2222
"os"
2323
"strings"
24+
"text/template"
2425
"time"
2526

2627
log "github.com/Sirupsen/logrus"
28+
"github.com/gin-gonic/gin"
2729
)
2830

2931
var (
@@ -215,3 +217,20 @@ func generateCertificates() {
215217
log.Print("written cert.cer")
216218

217219
}
220+
221+
func certHandler(c *gin.Context) {
222+
if strings.Contains(c.Request.UserAgent(), "Firefox") {
223+
c.Header("content-type", "application/x-x509-ca-cert")
224+
c.File("ca.cert.cer")
225+
return
226+
}
227+
noFirefoxTemplate.Execute(c.Writer, c.Request.Host)
228+
}
229+
230+
const noFirefoxTemplateHTML = `<!DOCTYPE html>
231+
232+
233+
234+
`
235+
236+
var noFirefoxTemplate = template.Must(template.New("home").Parse(noFirefoxTemplateHTML))

main.go

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,6 @@ func launchSelfLater() {
7575
log.Println("Done waiting 2 secs. Now launching...")
7676
}
7777

78-
func certHandler(c *gin.Context) {
79-
c.Header("content-type", "application/x-x509-ca-cert")
80-
c.File("cert.cer")
81-
}
82-
8378
func main() {
8479

8580
flag.Parse()
@@ -236,6 +231,8 @@ func main() {
236231
ValidateHeaders: false,
237232
}))
238233

234+
r.LoadHTMLFiles("templates/nofirefox.html")
235+
239236
r.GET("/", homeHandler)
240237
r.GET("/certificate.crt", certHandler)
241238
r.POST("/upload", uploadHandler)

0 commit comments

Comments
 (0)