This commit is contained in:
@@ -31,6 +31,8 @@ const (
|
|||||||
ctxDecryptedQueryKey = "decrypted_query"
|
ctxDecryptedQueryKey = "decrypted_query"
|
||||||
ctxEncryptedBodyKey = "encrypted_request_body"
|
ctxEncryptedBodyKey = "encrypted_request_body"
|
||||||
ctxDecryptedBodyKey = "decrypted_request_body"
|
ctxDecryptedBodyKey = "decrypted_request_body"
|
||||||
|
|
||||||
|
deviceDecryptSkipPathPublicFileUpload = "/v1/public/file/upload"
|
||||||
)
|
)
|
||||||
|
|
||||||
func DeviceMiddleware(srvCtx *svc.ServiceContext) func(c *gin.Context) {
|
func DeviceMiddleware(srvCtx *svc.ServiceContext) func(c *gin.Context) {
|
||||||
@@ -70,6 +72,14 @@ func DeviceMiddleware(srvCtx *svc.ServiceContext) func(c *gin.Context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
rw := NewResponseWriter(c, srvCtx)
|
rw := NewResponseWriter(c, srvCtx)
|
||||||
|
if shouldSkipDeviceRequestDecrypt(c) {
|
||||||
|
c.Set(ctxDeviceDecryptStatusKey, "skipped")
|
||||||
|
c.Set(ctxDeviceDecryptReasonKey, "multipart_upload_passthrough")
|
||||||
|
c.Writer = rw
|
||||||
|
c.Next()
|
||||||
|
rw.FlushAbort()
|
||||||
|
return
|
||||||
|
}
|
||||||
if !rw.Decrypt() {
|
if !rw.Decrypt() {
|
||||||
c.Set(ctxDeviceDecryptStatusKey, "failed")
|
c.Set(ctxDeviceDecryptStatusKey, "failed")
|
||||||
if _, exists := c.Get(ctxDeviceDecryptReasonKey); !exists {
|
if _, exists := c.Get(ctxDeviceDecryptReasonKey); !exists {
|
||||||
@@ -85,6 +95,13 @@ func DeviceMiddleware(srvCtx *svc.ServiceContext) func(c *gin.Context) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func shouldSkipDeviceRequestDecrypt(c *gin.Context) bool {
|
||||||
|
if c.Request.URL.Path != deviceDecryptSkipPathPublicFileUpload {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
return strings.HasPrefix(strings.ToLower(strings.TrimSpace(c.GetHeader("Content-Type"))), "multipart/form-data")
|
||||||
|
}
|
||||||
|
|
||||||
func NewResponseWriter(c *gin.Context, srvCtx *svc.ServiceContext) (rw *ResponseWriter) {
|
func NewResponseWriter(c *gin.Context, srvCtx *svc.ServiceContext) (rw *ResponseWriter) {
|
||||||
rw = &ResponseWriter{
|
rw = &ResponseWriter{
|
||||||
c: c,
|
c: c,
|
||||||
|
|||||||
Reference in New Issue
Block a user