mirror of
https://github.com/minoplhy/chibisafe-netproxy.git
synced 2025-04-19 23:36:57 +00:00
Compare commits
No commits in common. "master" and "v0.2.2" have entirely different histories.
21
LICENSE
21
LICENSE
@ -1,21 +0,0 @@
|
|||||||
MIT License
|
|
||||||
|
|
||||||
Copyright (c) 2024 Minoplhy
|
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
|
||||||
in the Software without restriction, including without limitation the rights
|
|
||||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
|
||||||
furnished to do so, subject to the following conditions:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in all
|
|
||||||
copies or substantial portions of the Software.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
SOFTWARE.
|
|
@ -53,12 +53,11 @@ func UploadPost(BasePath string, headers map[string]string, PostData UploadPostM
|
|||||||
defer resp.Body.Close()
|
defer resp.Body.Close()
|
||||||
|
|
||||||
if resp.StatusCode == http.StatusOK {
|
if resp.StatusCode == http.StatusOK {
|
||||||
buffer := bytes.NewBuffer(nil)
|
BodyRead, err := io.ReadAll(resp.Body)
|
||||||
_, err := io.Copy(buffer, resp.Body)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return buffer.Bytes(), nil
|
return BodyRead, nil
|
||||||
} else {
|
} else {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -100,12 +99,11 @@ func NetworkStoragePut(URL string, ContentType string, filepath string) ([]byte,
|
|||||||
defer resp.Body.Close()
|
defer resp.Body.Close()
|
||||||
|
|
||||||
if resp.StatusCode == http.StatusOK {
|
if resp.StatusCode == http.StatusOK {
|
||||||
buffer := bytes.NewBuffer(nil)
|
BodyRead, err := io.ReadAll(resp.Body)
|
||||||
_, err := io.Copy(buffer, resp.Body)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return buffer.Bytes(), nil
|
return BodyRead, nil
|
||||||
} else {
|
} else {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -129,15 +127,13 @@ func UploadProcessPost(BasePath string, headers map[string]string, PostData Uplo
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
defer resp.Body.Close()
|
|
||||||
|
|
||||||
if resp.StatusCode == http.StatusOK {
|
if resp.StatusCode == http.StatusOK {
|
||||||
buffer := bytes.NewBuffer(nil)
|
BodyRead, err := io.ReadAll(resp.Body)
|
||||||
_, err := io.Copy(buffer, resp.Body)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return buffer.Bytes(), nil
|
return BodyRead, nil
|
||||||
} else {
|
} else {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -75,5 +75,5 @@ func HTTPClientDo(Request *http.Request) (*http.Response, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return response, nil
|
return response, err
|
||||||
}
|
}
|
||||||
|
@ -5,8 +5,8 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Check if request IP Address is in internal ranges
|
|
||||||
func IsInternalIP(ip string) bool {
|
func IsInternalIP(ip string) bool {
|
||||||
|
|
||||||
parts := strings.Split(ip, ":")
|
parts := strings.Split(ip, ":")
|
||||||
ip = parts[0]
|
ip = parts[0]
|
||||||
|
|
||||||
|
@ -2,28 +2,18 @@ package handler
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"net/http"
|
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/rs/zerolog/log"
|
"github.com/rs/zerolog/log"
|
||||||
)
|
)
|
||||||
|
|
||||||
func ResponseBuild(w http.ResponseWriter, ContentType string, ContentData []byte) {
|
func ErrorResponseBuild(StatusCode int64, Message string) string {
|
||||||
w.Header().Set("Content-Type", ContentType)
|
|
||||||
w.WriteHeader(http.StatusOK)
|
|
||||||
w.Write(ContentData)
|
|
||||||
}
|
|
||||||
|
|
||||||
func ErrorResponseBuild(w http.ResponseWriter, StatusCode int64, Message string) {
|
|
||||||
ErrorResponse := ErrorResponse{
|
ErrorResponse := ErrorResponse{
|
||||||
StatusCode: StatusCode,
|
StatusCode: StatusCode,
|
||||||
Message: Message,
|
Message: Message,
|
||||||
}
|
}
|
||||||
Response, _ := json.Marshal(ErrorResponse)
|
Response, _ := json.Marshal(ErrorResponse)
|
||||||
|
return string(Response)
|
||||||
w.Header().Set("Content-Type", "application/json")
|
|
||||||
w.WriteHeader(int(StatusCode))
|
|
||||||
w.Write(Response)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func InfoLogBuilder(headers []string, message string) {
|
func InfoLogBuilder(headers []string, message string) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user