mirror of
https://github.com/minoplhy/chibisafe-netproxy.git
synced 2024-11-24 12:37:06 +00:00
add: X-Real-IP header
This commit is contained in:
parent
449b455d24
commit
897e0497d8
@ -1,6 +1,6 @@
|
||||
# syntax=docker/dockerfile:1
|
||||
|
||||
FROM golang:latest
|
||||
FROM golang:1.22
|
||||
|
||||
# Set destination for COPY
|
||||
WORKDIR /app
|
||||
|
16
main.go
16
main.go
@ -85,7 +85,13 @@ func uploadHandler(w http.ResponseWriter, r *http.Request) {
|
||||
FileSize: fileHeader.Size,
|
||||
}
|
||||
|
||||
chibisafe_post, err := handler.UploadPost(Chibisafe_basepath, API_Key, PostData)
|
||||
UploadHeaders := map[string]string{
|
||||
"X-Api-Key": API_Key,
|
||||
"Content-Type": "application/json",
|
||||
"X-Real-IP": r.RemoteAddr,
|
||||
}
|
||||
|
||||
chibisafe_post, err := handler.UploadPost(Chibisafe_basepath, UploadHeaders, PostData)
|
||||
if err != nil {
|
||||
http.Error(w, handler.ErrorResponseBuild(http.StatusBadRequest, "Something went wrong!"), http.StatusBadRequest)
|
||||
handler.ErrorLogBuilder([]string{r.RemoteAddr, tempfilepath}, err.Error())
|
||||
@ -120,7 +126,13 @@ func uploadHandler(w http.ResponseWriter, r *http.Request) {
|
||||
Identifier: chibisafe_Response_Metadata.Identifier,
|
||||
}
|
||||
|
||||
PostProcess, err := handler.UploadProcessPost(Chibisafe_basepath, API_Key, PostProcessData)
|
||||
ProcessHeaders := map[string]string{
|
||||
"X-Api-Key": API_Key,
|
||||
"Content-Type": "application/json",
|
||||
"X-Real-IP": r.RemoteAddr,
|
||||
}
|
||||
|
||||
PostProcess, err := handler.UploadProcessPost(Chibisafe_basepath, ProcessHeaders, PostProcessData)
|
||||
if err != nil {
|
||||
http.Error(w, handler.ErrorResponseBuild(http.StatusInternalServerError, "Something went wrong!"), http.StatusInternalServerError)
|
||||
handler.ErrorLogBuilder([]string{r.RemoteAddr, chibisafe_Response_Metadata.Identifier, tempfilepath}, err.Error())
|
||||
|
@ -31,7 +31,7 @@ func Check_API_Key(Basepath string, accessKey string) bool {
|
||||
return resp.StatusCode == http.StatusOK
|
||||
}
|
||||
|
||||
func UploadPost(BasePath string, accessKey string, PostData UploadPostMeta) ([]byte, error) {
|
||||
func UploadPost(BasePath string, headers map[string]string, PostData UploadPostMeta) ([]byte, error) {
|
||||
URL := BasePath + "/api/upload"
|
||||
// Convert PostData to JSON
|
||||
PostDataJson, err := json.Marshal(PostData)
|
||||
@ -39,11 +39,6 @@ func UploadPost(BasePath string, accessKey string, PostData UploadPostMeta) ([]b
|
||||
return nil, err
|
||||
}
|
||||
|
||||
headers := map[string]string{
|
||||
"X-Api-Key": accessKey,
|
||||
"Content-Type": "application/json",
|
||||
}
|
||||
|
||||
POSTStruct := URLRequest{
|
||||
URL: URL,
|
||||
ContentType: PostData.ContentType,
|
||||
@ -114,7 +109,7 @@ func NetworkStoragePut(URL string, ContentType string, filepath string) ([]byte,
|
||||
}
|
||||
}
|
||||
|
||||
func UploadProcessPost(BasePath string, accessKey string, PostData UploadProcessMeta) ([]byte, error) {
|
||||
func UploadProcessPost(BasePath string, headers map[string]string, PostData UploadProcessMeta) ([]byte, error) {
|
||||
URL := BasePath + "/api/upload/process"
|
||||
// Convert PostData to JSON
|
||||
PostDataJson, err := json.Marshal(PostData)
|
||||
@ -122,11 +117,6 @@ func UploadProcessPost(BasePath string, accessKey string, PostData UploadProcess
|
||||
return nil, err
|
||||
}
|
||||
|
||||
headers := map[string]string{
|
||||
"X-Api-Key": accessKey,
|
||||
"Content-Type": "application/json",
|
||||
}
|
||||
|
||||
POSTStruct := URLRequest{
|
||||
URL: URL,
|
||||
Method: "POST",
|
||||
|
Loading…
Reference in New Issue
Block a user