Commit 28f39a1a authored by Sietse Ringers's avatar Sietse Ringers
Browse files

Disable server sent events by default

parent 19844154
Pipeline #19772 failed with stages
in 2 minutes and 33 seconds
......@@ -223,6 +223,10 @@ func ParsePath(path string) (string, string, error) {
}
func (s *Server) SubscribeServerSentEvents(w http.ResponseWriter, r *http.Request, token string, requestor bool) error {
if !s.conf.EnableSSE {
return errors.New("Server sent events disabled")
}
var session *session
if requestor {
session = s.sessions.get(token)
......
......@@ -47,6 +47,8 @@ type Configuration struct {
// See https://github.com/privacybydesign/irmago/tree/master/server#specifying-an-email-address
// for more information
Email string `json:"email" mapstructure:"email"`
// Enable server sent events for status updates (experimental; tends to hang when a reverse proxy is used)
EnableSSE bool
}
type SessionPackage struct {
......
......@@ -83,6 +83,7 @@ func setFlags(cmd *cobra.Command) error {
flags.String("static-path", "", "Host files under this path as static files (leave empty to disable)")
flags.String("static-prefix", "/", "Host static files under this URL prefix")
flags.StringP("url", "u", defaulturl, "external URL to server to which the IRMA client connects")
flags.Bool("sse", false, "Enable server sent for status updates (experimental)")
flags.IntP("port", "p", 8088, "port at which to listen")
flags.StringP("listen-addr", "l", "", "address at which to listen (default 0.0.0.0)")
......@@ -185,9 +186,10 @@ func configure(cmd *cobra.Command) error {
SchemesUpdateInterval: viper.GetInt("schemes-update"),
DisableSchemesUpdate: viper.GetInt("schemes-update") == 0,
IssuerPrivateKeysPath: viper.GetString("privkeys"),
URL: viper.GetString("url"),
Email: viper.GetString("email"),
Logger: logger,
URL: viper.GetString("url"),
Email: viper.GetString("email"),
EnableSSE: viper.GetBool("sse"),
Logger: logger,
},
Permissions: requestorserver.Permissions{
Disclosing: handlePermission("disclose-perms"),
......
......@@ -129,7 +129,11 @@ func (s *Server) HandlerFunc() http.HandlerFunc {
token, noun, err := servercore.ParsePath(r.URL.Path)
if err == nil && noun == "statusevents" { // if err != nil we let it be handled by HandleProtocolMessage below
if err = s.SubscribeServerSentEvents(w, r, token, false); err != nil {
server.WriteError(w, server.ErrorUnexpectedRequest, err.Error())
server.WriteResponse(w, nil, &irma.RemoteError{
Status: server.ErrorUnsupported.Status,
ErrorName: string(server.ErrorUnsupported.Type),
Description: server.ErrorUnsupported.Description,
})
}
return
}
......
......@@ -295,7 +295,11 @@ func (s *Server) handleStatusEvents(w http.ResponseWriter, r *http.Request) {
token := chi.URLParam(r, "token")
s.conf.Logger.WithFields(logrus.Fields{"session": token}).Debug("new client subscribed to server sent events")
if err := s.irmaserv.SubscribeServerSentEvents(w, r, token, true); err != nil {
server.WriteError(w, server.ErrorUnexpectedRequest, err.Error())
server.WriteResponse(w, nil, &irma.RemoteError{
Status: server.ErrorUnsupported.Status,
ErrorName: string(server.ErrorUnsupported.Type),
Description: server.ErrorUnsupported.Description,
})
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment