Commit 708e75b7 authored by Sietse Ringers's avatar Sietse Ringers
Browse files

Remove parameter from irmarequestor.HttpHandlerFunc()

parent 91166ae1
...@@ -29,17 +29,15 @@ func Initialize(configuration *server.Configuration) error { ...@@ -29,17 +29,15 @@ func Initialize(configuration *server.Configuration) error {
if conf.IrmaConfiguration == nil { if conf.IrmaConfiguration == nil {
var err error var err error
var path, assets string
if conf.CachePath == "" { if conf.CachePath == "" {
conf.CachePath, err = CachePath() path = conf.IrmaConfigurationPath
if err != nil { assets = ""
return err } else {
} path = filepath.Join(conf.CachePath, "irma_configuration")
conf.CachePath = filepath.Join(conf.CachePath, "irmalibrary") assets = conf.IrmaConfigurationPath
} }
conf.IrmaConfiguration, err = irma.NewConfiguration( conf.IrmaConfiguration, err = irma.NewConfiguration(path, assets)
filepath.Join(conf.CachePath, "irma_configuration"),
conf.IrmaConfigurationPath,
)
if err != nil { if err != nil {
return err return err
} }
...@@ -164,8 +162,9 @@ func HandleProtocolMessage( ...@@ -164,8 +162,9 @@ func HandleProtocolMessage(
path = path[:len(path)-1] path = path[:len(path)-1]
} }
} }
conf.Logger.Debugf("Routing protocol message: %s %s", method, path) conf.Logger.Debugf("Routing protocol message: %s %s", method, path)
pattern := regexp.MustCompile("(\\w+)/?(\\w*)") pattern := regexp.MustCompile("(\\w+)/?(|commitments|proofs|status)$")
matches := pattern.FindStringSubmatch(path) matches := pattern.FindStringSubmatch(path)
if len(matches) != 3 { if len(matches) != 3 {
conf.Logger.Warnf("Invalid URL: %s", path) conf.Logger.Warnf("Invalid URL: %s", path)
......
...@@ -48,15 +48,10 @@ func CancelSession(token string) error { ...@@ -48,15 +48,10 @@ func CancelSession(token string) error {
// with IRMA apps. Initialize() must be called before this. // with IRMA apps. Initialize() must be called before this.
// //
// Example usage: // Example usage:
// http.HandleFunc("/irma/", irmarequestor.HttpHandlerFunc("/irma/")) // http.HandleFunc("/irma/", irmarequestor.HttpHandlerFunc())
// //
// The IRMA app can then perform IRMA sessions at https://example.com/irma. // The IRMA app can then perform IRMA sessions at https://example.com/irma.
// Note that the two strings must be equal, i.e. you must pass the pattern at which func HttpHandlerFunc() http.HandlerFunc {
// you register the handler.
func HttpHandlerFunc(pattern string) http.HandlerFunc {
if len(pattern) != 0 && pattern[0] != '/' {
pattern = "/" + pattern
}
return func(w http.ResponseWriter, r *http.Request) { return func(w http.ResponseWriter, r *http.Request) {
var message []byte var message []byte
message, err := ioutil.ReadAll(r.Body) message, err := ioutil.ReadAll(r.Body)
...@@ -64,8 +59,7 @@ func HttpHandlerFunc(pattern string) http.HandlerFunc { ...@@ -64,8 +59,7 @@ func HttpHandlerFunc(pattern string) http.HandlerFunc {
w.WriteHeader(http.StatusInternalServerError) w.WriteHeader(http.StatusInternalServerError)
return return
} }
path := r.URL.Path[len(pattern):] status, response, result := backend.HandleProtocolMessage(r.URL.Path, r.Method, r.Header, message)
status, response, result := backend.HandleProtocolMessage(path, r.Method, r.Header, message)
w.WriteHeader(status) w.WriteHeader(status)
w.Write(response) w.Write(response)
if result != nil { if result != nil {
......
...@@ -60,7 +60,7 @@ func Handler(config *Configuration) (http.Handler, error) { ...@@ -60,7 +60,7 @@ func Handler(config *Configuration) (http.Handler, error) {
}).Handler) }).Handler)
// Mount server for irmaclient // Mount server for irmaclient
router.Mount("/irma/", irmarequestor.HttpHandlerFunc("/irma/")) router.Mount("/irma/", irmarequestor.HttpHandlerFunc())
// Server routes // Server routes
router.Post("/session", handleCreate) router.Post("/session", handleCreate)
......
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