File tree Expand file tree Collapse file tree 2 files changed +21
-5
lines changed
Expand file tree Collapse file tree 2 files changed +21
-5
lines changed Original file line number Diff line number Diff 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
2931var (
@@ -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 ))
Original file line number Diff line number Diff 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-
8378func 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 )
You can’t perform that action at this time.
0 commit comments