Changes
1 changed files (+29/-32)
-
-
@@ -22,11 +22,11 @@ func (a ActivityHandlerFn) ValidMethod(r *http.Request) bool {} // ValidateRequest validates if the current handler can process the current request func (a ActivityHandlerFn) ValidateRequest(r *http.Request) error { func (a ActivityHandlerFn) ValidateRequest(r *http.Request) (int, error) { if !a.ValidMethod(r) { return fmt.Errorf("invalid HTTP method %s", r.Method) return http.StatusNotAcceptable, fmt.Errorf("invalid HTTP method %s", r.Method) } return nil return http.StatusOK, nil } // ServeHTTP implements the http.Handler interface for the ActivityHandlerFn type
-
@@ -34,12 +34,10 @@ func (a ActivityHandlerFn) ServeHTTP(w http.ResponseWriter, r *http.Request) {var dat []byte var iri as.IRI var err error var status = http.StatusOK if !a.ValidMethod(r) { status = http.StatusNotAcceptable dat = []byte(fmt.Errorf("invalid HTTP method").Error()) if status, err = a.ValidateRequest(r); err != nil { dat = []byte(err.Error()) } if iri, status, err = a(w, r); err != nil {
-
@@ -57,8 +55,7 @@ func (a ActivityHandlerFn) ServeHTTP(w http.ResponseWriter, r *http.Request) {} type ClientHandler interface { ValidMethod(r *http.Request) bool // ?? ValidateRequest(r *http.Request) error ValidateRequest(r *http.Request) (int, error) } // CollectionHandlerFn is the type that we're using to represent handlers that will return ActivityStreams
-
@@ -67,15 +64,15 @@ type CollectionHandlerFn func(http.ResponseWriter, *http.Request) (as.Collection// ValidMethod validates if the current handler can process the current request func (c CollectionHandlerFn) ValidMethod(r *http.Request) bool { return r.Method != http.MethodGet && r.Method != http.MethodHead return r.Method == http.MethodGet || r.Method == http.MethodHead } // ValidateRequest validates if the current handler can process the current request func (c CollectionHandlerFn) ValidateRequest(r *http.Request) error { func (c CollectionHandlerFn) ValidateRequest(r *http.Request) (int, error) { if !c.ValidMethod(r) { return fmt.Errorf("invalid HTTP method %s", r.Method) return http.StatusMethodNotAllowed, fmt.Errorf("invalid HTTP method %s", r.Method) } return nil return http.StatusOK, nil } // ServeHTTP implements the http.Handler interface for the CollectionHandlerFn type
-
@@ -83,18 +80,18 @@ func (c CollectionHandlerFn) ServeHTTP(w http.ResponseWriter, r *http.Request) {var dat []byte var status = http.StatusOK var err error if c.ValidMethod(r) { status = http.StatusNotAcceptable dat = []byte(fmt.Errorf("invalid HTTP method").Error()) } if col, err := c(w, r); err != nil { if status, err = c.ValidateRequest(r); err != nil { dat = []byte(err.Error()) } else { if dat, err = j.WithContext(j.IRI(as.ActivityBaseURI)).Marshal(col); err != nil { status = http.StatusInternalServerError if col, err := c(w, r); err != nil { dat = []byte(err.Error()) } else { if dat, err = j.WithContext(j.IRI(as.ActivityBaseURI)).Marshal(col); err != nil { status = http.StatusInternalServerError dat = []byte(err.Error()) } } }
-
@@ -114,30 +111,30 @@ func (i ItemHandlerFn) ValidMethod( r *http.Request) bool {} // ValidateRequest validates if the current handler can process the current request func (i ItemHandlerFn) ValidateRequest(r *http.Request) error { func (i ItemHandlerFn) ValidateRequest(r *http.Request) (int, error) { if !i.ValidMethod(r) { return fmt.Errorf("invalid HTTP method %s", r.Method) return http.StatusMethodNotAllowed, fmt.Errorf("invalid HTTP method %s", r.Method) } return nil return http.StatusOK, nil } // ServeHTTP implements the http.Handler interface for the ItemHandlerFn type func (i ItemHandlerFn) ServeHTTP(w http.ResponseWriter, r *http.Request) { var dat []byte var status = http.StatusOK var err error if i.ValidMethod(r) { status = http.StatusNotAcceptable dat = []byte(fmt.Errorf("invalid HTTP method").Error()) } if it, err := i(w, r); err != nil { status = http.StatusInternalServerError if status, err = i.ValidateRequest(r); err != nil { dat = []byte(err.Error()) } else { if dat, err = j.WithContext(j.IRI(as.ActivityBaseURI)).Marshal(it); err != nil { if it, err := i(w, r); err != nil { status = http.StatusInternalServerError dat = []byte(err.Error()) } else { if dat, err = j.WithContext(j.IRI(as.ActivityBaseURI)).Marshal(it); err != nil { status = http.StatusInternalServerError dat = []byte(err.Error()) } } }
-