Skip to content

Commit

Permalink
fix pipeline issue
Browse files Browse the repository at this point in the history
  • Loading branch information
Elbahkiry committed Sep 20, 2024
1 parent 3124fab commit 3327fd2
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
11 changes: 9 additions & 2 deletions service/services/clamav/clamav.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,14 @@ func (c *Clamav) Processing(partial bool, IcapHeader textproto.MIMEHeader) (int,
if err != nil {
fmt.Println(err.Error())
}
fileSize := fmt.Sprintf("%v", len(file))
var size int
if c.methodName == utils.ICAPModeResp {
size64, _ := c.httpMsg.StorageClient.Size(c.httpMsg.StorageKey)
size = int(size64) // Convert int64 to int
} else {
size = len(file)
}
fileSize := fmt.Sprintf("%v", size)
fileHash := hex.EncodeToString(hash.Sum([]byte(nil)))
logging.Logger.Info(utils.PrepareLogMsg(c.xICAPMetadata, c.serviceName+" file hash : "+fileHash))
isProcess, icapStatus, httpMsg := c.generalFunc.CheckTheExtension(fileExtension, c.extArrs,
Expand All @@ -109,7 +116,7 @@ func (c *Clamav) Processing(partial bool, IcapHeader textproto.MIMEHeader) (int,

//check if the file size is greater than max file size of the service
//if yes we will return 200 ok or 204 no modification, it depends on the configuration of the service
if c.maxFileSize != 0 && c.maxFileSize < len(file) && isProcess {
if c.maxFileSize != 0 && c.maxFileSize < size && isProcess {
status, file, httpMsg := c.generalFunc.IfMaxFileSizeExc(c.returnOrigIfMaxSizeExc, c.serviceName, c.methodName, bytes.NewBuffer(file), c.maxFileSize, ExceptionPagePath, fileSize)
fileAfterPrep, httpMsg := c.generalFunc.IfStatusIs204WithFile(c.methodName, status, file, isGzip, reqContentType, httpMsg, true)
if fileAfterPrep == nil && httpMsg == nil {
Expand Down
13 changes: 11 additions & 2 deletions service/services/echo/echo.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,16 @@ func (e *Echo) Processing(partial bool, IcapHeader textproto.MIMEHeader) (int, i
return icapStatus, httpMsg, serviceHeaders, msgHeadersBeforeProcessing,
msgHeadersAfterProcessing, vendorMsgs
}

var size int
if e.methodName == utils.ICAPModeResp {
size64, _ := e.httpMsg.StorageClient.Size(e.httpMsg.StorageKey)
size = int(size64) // Convert int64 to int
} else {
size = len(file)
}
//check if the file size is greater than max file size of the service
//if yes we will return 200 ok or 204 no modification, it depends on the configuration of the service
if e.maxFileSize != 0 && e.maxFileSize < len(file) && isProcess {
if e.maxFileSize != 0 && e.maxFileSize < size && isProcess {
status, file, httpMsgAfter := e.generalFunc.IfMaxFileSizeExc(e.returnOrigIfMaxSizeExc, e.serviceName, e.methodName, bytes.NewBuffer(file), e.maxFileSize, utils.BlockPagePath, fileSize)
fileAfterPrep, httpMsgAfter := e.generalFunc.IfStatusIs204WithFile(e.methodName, status, file, isGzip, reqContentType, httpMsgAfter, true)
if fileAfterPrep == nil && httpMsgAfter == nil {
Expand All @@ -105,9 +111,12 @@ func (e *Echo) Processing(partial bool, IcapHeader textproto.MIMEHeader) (int, i
}

scannedFile := file
fmt.Println(len(scannedFile))

//returning the scanned file if everything is ok
scannedFile = e.generalFunc.PreparingFileAfterScanning(scannedFile, reqContentType, e.methodName)
fmt.Println(len(scannedFile))

msgHeadersAfterProcessing = e.generalFunc.LogHTTPMsgHeaders(e.methodName)
logging.Logger.Info(utils.PrepareLogMsg(e.xICAPMetadata, e.serviceName+" service has stopped processing"))
return utils.OkStatusCodeStr, e.generalFunc.ReturningHttpMessageWithFile(e.methodName, scannedFile),
Expand Down

0 comments on commit 3327fd2

Please sign in to comment.