mirror of
https://github.com/minoplhy/chibisafe-netproxy.git
synced 2024-12-22 10:08:08 +00:00
enhance: memory handling
This commit is contained in:
parent
f269bfaa9c
commit
22c23cc2ee
2
main.go
2
main.go
@ -77,7 +77,6 @@ func uploadHandler(w http.ResponseWriter, r *http.Request) {
|
||||
tempfilepath := handler.GetTempFilename(fileHeader.Filename)
|
||||
handler.InfoLogBuilder([]string{r.RemoteAddr, tempfilepath}, "Successfully obtained temporary Filename")
|
||||
handler.SaveFile(tempfilepath, file)
|
||||
handler.DiscardFile(file)
|
||||
|
||||
PostData := handler.UploadPostMeta{
|
||||
ContentType: fileHeader.Header.Get("Content-Type"),
|
||||
@ -152,7 +151,6 @@ func uploadHandler(w http.ResponseWriter, r *http.Request) {
|
||||
if err != nil {
|
||||
http.Error(w, handler.ErrorResponseBuild(http.StatusInternalServerError, "Something went wrong!"), http.StatusInternalServerError)
|
||||
handler.ErrorLogBuilder([]string{}, err.Error())
|
||||
|
||||
return
|
||||
}
|
||||
handler.InfoLogBuilder([]string{r.RemoteAddr, PostProcessResponse.Name, tempfilepath}, fmt.Sprintf("Successfully Processed Response with UUID: %s", PostProcessResponse.UUID))
|
||||
|
@ -53,11 +53,13 @@ func UploadPost(BasePath string, headers map[string]string, PostData UploadPostM
|
||||
defer resp.Body.Close()
|
||||
|
||||
if resp.StatusCode == http.StatusOK {
|
||||
BodyRead, err := io.ReadAll(resp.Body)
|
||||
buffer := bytes.NewBuffer(nil)
|
||||
_, err := io.Copy(buffer, resp.Body)
|
||||
defer resp.Body.Close()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return BodyRead, nil
|
||||
return buffer.Bytes(), nil
|
||||
} else {
|
||||
return nil, err
|
||||
}
|
||||
@ -96,14 +98,15 @@ func NetworkStoragePut(URL string, ContentType string, filepath string) ([]byte,
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
if resp.StatusCode == http.StatusOK {
|
||||
BodyRead, err := io.ReadAll(resp.Body)
|
||||
buffer := bytes.NewBuffer(nil)
|
||||
_, err := io.Copy(buffer, resp.Body)
|
||||
defer resp.Body.Close()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return BodyRead, nil
|
||||
return buffer.Bytes(), nil
|
||||
} else {
|
||||
return nil, err
|
||||
}
|
||||
@ -129,11 +132,13 @@ func UploadProcessPost(BasePath string, headers map[string]string, PostData Uplo
|
||||
}
|
||||
|
||||
if resp.StatusCode == http.StatusOK {
|
||||
BodyRead, err := io.ReadAll(resp.Body)
|
||||
buffer := bytes.NewBuffer(nil)
|
||||
_, err := io.Copy(buffer, resp.Body)
|
||||
defer resp.Body.Close()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return BodyRead, nil
|
||||
return buffer.Bytes(), nil
|
||||
} else {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -75,5 +75,5 @@ func HTTPClientDo(Request *http.Request) (*http.Response, error) {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return response, err
|
||||
return response, nil
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user