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 {
if conf.IrmaConfiguration == nil {
var err error
var path, assets string
if conf.CachePath == "" {
conf.CachePath, err = CachePath()
if err != nil {
return err
}
conf.CachePath = filepath.Join(conf.CachePath, "irmalibrary")
path = conf.IrmaConfigurationPath
assets = ""
} else {
path = filepath.Join(conf.CachePath, "irma_configuration")
assets = conf.IrmaConfigurationPath
}
conf.IrmaConfiguration, err = irma.NewConfiguration(
filepath.Join(conf.CachePath, "irma_configuration"),
conf.IrmaConfigurationPath,
)
conf.IrmaConfiguration, err = irma.NewConfiguration(path, assets)
if err != nil {
return err
}
......@@ -164,8 +162,9 @@ func HandleProtocolMessage(
path = path[:len(path)-1]
}
}
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)
if len(matches) != 3 {
conf.Logger.Warnf("Invalid URL: %s", path)
......
......@@ -48,15 +48,10 @@ func CancelSession(token string) error {
// with IRMA apps. Initialize() must be called before this.
//
// 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.
// Note that the two strings must be equal, i.e. you must pass the pattern at which
// you register the handler.
func HttpHandlerFunc(pattern string) http.HandlerFunc {
if len(pattern) != 0 && pattern[0] != '/' {
pattern = "/" + pattern
}
func HttpHandlerFunc() http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var message []byte
message, err := ioutil.ReadAll(r.Body)
......@@ -64,8 +59,7 @@ func HttpHandlerFunc(pattern string) http.HandlerFunc {
w.WriteHeader(http.StatusInternalServerError)
return
}
path := r.URL.Path[len(pattern):]
status, response, result := backend.HandleProtocolMessage(path, r.Method, r.Header, message)
status, response, result := backend.HandleProtocolMessage(r.URL.Path, r.Method, r.Header, message)
w.WriteHeader(status)
w.Write(response)
if result != nil {
......
......@@ -60,7 +60,7 @@ func Handler(config *Configuration) (http.Handler, error) {
}).Handler)
// Mount server for irmaclient
router.Mount("/irma/", irmarequestor.HttpHandlerFunc("/irma/"))
router.Mount("/irma/", irmarequestor.HttpHandlerFunc())
// Server routes
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