|
@@ -1,6 +1,8 @@
|
|
package httpserver
|
|
package httpserver
|
|
|
|
|
|
import (
|
|
import (
|
|
|
|
+ "fmt"
|
|
|
|
+ "io"
|
|
"net/http"
|
|
"net/http"
|
|
|
|
|
|
"github.com/gin-gonic/gin"
|
|
"github.com/gin-gonic/gin"
|
|
@@ -23,6 +25,38 @@ func NewController(cfg *HttpServerConfig) *Controller {
|
|
This handler will be responsible for proxying out the GET requests that the server recieves
|
|
This handler will be responsible for proxying out the GET requests that the server recieves
|
|
*/
|
|
*/
|
|
func (c *Controller) Get(ctx *gin.Context) {
|
|
func (c *Controller) Get(ctx *gin.Context) {
|
|
|
|
+ url := fmt.Sprintf("https://%s%s", c.Config.RevProxySite, ctx.Param("ProxiedPath"))
|
|
|
|
+ req, err := http.NewRequest("GET", url, nil)
|
|
|
|
+ if err != nil {
|
|
|
|
+ ctx.JSON(500, map[string]string{
|
|
|
|
+ "Error": "Error creating the request.",
|
|
|
|
+ "Msg:": err.Error(),
|
|
|
|
+ })
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+ req.URL.Path = ctx.Param("ProxiedPath")
|
|
|
|
+ req.Header.Add("user-agent", c.Config.UserAgent)
|
|
|
|
+ req.Header.Add("Referer", c.Config.AllowedDomain)
|
|
|
|
+ // fmt.Printf("%+v\n", req)
|
|
|
|
+ client := &http.Client{}
|
|
|
|
+ resp, err := client.Do(req)
|
|
|
|
+ if err != nil {
|
|
|
|
+ ctx.JSON(500, map[string]string{
|
|
|
|
+ "Error": "Error creating the request.",
|
|
|
|
+ "Msg:": err.Error(),
|
|
|
|
+ })
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+ defer resp.Body.Close()
|
|
|
|
+ b, err := io.ReadAll(resp.Body)
|
|
|
|
+ if err != nil {
|
|
|
|
+ ctx.JSON(500, map[string]string{
|
|
|
|
+ "Error": "Error creating the request.",
|
|
|
|
+ "Msg:": err.Error(),
|
|
|
|
+ })
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+ ctx.Data(200, "text/html", b)
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
@@ -30,7 +64,8 @@ func (c *Controller) Get(ctx *gin.Context) {
|
|
This handler will be responsible for proxying any POST requests
|
|
This handler will be responsible for proxying any POST requests
|
|
*/
|
|
*/
|
|
func (c *Controller) Post(ctx *gin.Context) {
|
|
func (c *Controller) Post(ctx *gin.Context) {
|
|
- req, err := http.NewRequest()
|
|
|
|
|
|
+ url := fmt.Sprintf("%s/%s", c.Config.RevProxySite, ctx.FullPath())
|
|
|
|
+ req, err := http.NewRequest("POST", url, ctx.Request.Body)
|
|
if err != nil {
|
|
if err != nil {
|
|
ctx.JSON(500, map[string]string{
|
|
ctx.JSON(500, map[string]string{
|
|
"Error": "Error creating the request.",
|
|
"Error": "Error creating the request.",
|
|
@@ -40,8 +75,6 @@ func (c *Controller) Post(ctx *gin.Context) {
|
|
}
|
|
}
|
|
req.Header.Add("user-agent", c.Config.UserAgent)
|
|
req.Header.Add("user-agent", c.Config.UserAgent)
|
|
req.Header.Add("Referer", c.Config.AllowedDomain)
|
|
req.Header.Add("Referer", c.Config.AllowedDomain)
|
|
- req.Host = c.Config.RevProxySite
|
|
|
|
- req.Proto = ctx.Request.Method
|
|
|
|
- req.RequestURI = ctx.FullPath()
|
|
|
|
|
|
+ fmt.Printf("%+v\n", req)
|
|
|
|
|
|
}
|
|
}
|