This is an automated email from the ASF dual-hosted git repository.
ako pushed a commit to branch ageviewer_go
in repository https://gitbox.apache.org/repos/asf/age.git
The following commit(s) were added to refs/heads/ageviewer_go by this push:
new 3df3ae03 [VIEWER-DESKTOP-GO] error handling and validation (#765)
3df3ae03 is described below
commit 3df3ae033667d2fbf09b1a74940a883972459320
Author: marodins <[email protected]>
AuthorDate: Fri Mar 24 10:49:49 2023 -0700
[VIEWER-DESKTOP-GO] error handling and validation (#765)
* content-type validator for query group
* continue with other handlers using next
---
backend/age-viewer-go | Bin 8958071 -> 8961663 bytes
backend/main.go | 2 ++
backend/miscellaneous/content_type_validation.go | 24 +++++++++++++++++++++++
backend/routes/query.go | 2 +-
4 files changed, 27 insertions(+), 1 deletion(-)
diff --git a/backend/age-viewer-go b/backend/age-viewer-go
index 62fe6966..2d2e1c92 100755
Binary files a/backend/age-viewer-go and b/backend/age-viewer-go differ
diff --git a/backend/main.go b/backend/main.go
index dcc8a32c..0e3041fd 100644
--- a/backend/main.go
+++ b/backend/main.go
@@ -1,6 +1,7 @@
package main
import (
+ m "age-viewer-go/miscellaneous"
"age-viewer-go/models"
"age-viewer-go/routes"
"age-viewer-go/session"
@@ -16,6 +17,7 @@ func main() {
app.POST("/connect", routes.ConnectToDb)
cypher := app.Group("/query", routes.CypherMiddleWare)
+ cypher.Use(m.ValidateContentTypeMiddleWare)
cypher.POST("/metadata", routes.GraphMetaData)
cypher.POST("", routes.Cypher)
app.Start(":8080")
diff --git a/backend/miscellaneous/content_type_validation.go
b/backend/miscellaneous/content_type_validation.go
new file mode 100644
index 00000000..0b30c3aa
--- /dev/null
+++ b/backend/miscellaneous/content_type_validation.go
@@ -0,0 +1,24 @@
+package miscellaneous
+
+import (
+ "errors"
+ "fmt"
+ "net/http"
+
+ "github.com/labstack/echo"
+)
+
+func ValidateContentTypeMiddleWare(next echo.HandlerFunc) echo.HandlerFunc {
+ return func(ctx echo.Context) error {
+ val, ok := ctx.Request().Header["Content-Type"]
+ msg := fmt.Sprintf("expected %s, received %s",
"application/json", val)
+ if ok {
+ if fmt.Sprintf("%s", val) != "[application/json]" {
+ return
echo.NewHTTPError(http.StatusUnsupportedMediaType, errors.New(msg))
+ }
+ } else {
+ return
echo.NewHTTPError(http.StatusUnsupportedMediaType, errors.New(msg))
+ }
+ return next(ctx)
+ }
+}
diff --git a/backend/routes/query.go b/backend/routes/query.go
index f68500d7..c871ca80 100644
--- a/backend/routes/query.go
+++ b/backend/routes/query.go
@@ -79,7 +79,7 @@ func Cypher(ctx echo.Context) error {
}
cols, _ := rows.ColumnTypes()
- print("0 index val", cols[0].DatabaseTypeName())
+ //print("0 index val", cols[0].DatabaseTypeName())
if len(cols) == 1 && cols[0].DatabaseTypeName() == "VOID" {
return ctx.JSON(204, map[string]string{
"status": "success",