This commit is contained in:
DeniskaRediska committed 2019-10-21 17:12:34 +03:00
1 parent 7014f56cbb
commit fe6f1f5e5a
25 files changed
+1918

No files matched your search

+48
View File
@@ -0,0 +1,48 @@
package grpc
import (
"github.com/integration-system/isp-lib/backend"
u "github.com/integration-system/isp-lib/utils"
"github.com/valyala/fasthttp"
"isp-gate-service/proxy/grpc/handlers"
"isp-gate-service/proxy/grpc/utils"
"mime"
)
type Handler interface {
Complete(ctx *fasthttp.RequestCtx, method string, client *backend.RxGrpcClient)
}
func SetHandler(ctx *fasthttp.RequestCtx) Handler {
isMultipart := isMultipart(ctx)
isExpectFile := string(ctx.Request.Header.Peek(u.ExpectFileHeader)) == "true"
if isMultipart {
ctx.Response.Header.SetContentType(utils.JsonContentType)
return handlers.SendMultipartData
} else if isExpectFile {
return handlers.GetFile
} else {
ctx.Response.Header.SetContentType(utils.JsonContentType)
return handlers.Json
}
}
func isMultipart(ctx *fasthttp.RequestCtx) bool {
if !ctx.IsPost() {
return false
}
v := string(ctx.Request.Header.ContentType())
if v == "" {
return false
}
d, params, err := mime.ParseMediaType(v)
if err != nil || d != "multipart/form-data" {
return false
}
_, ok := params["boundary"]
if !ok {
return false
}
return true
}