make user-agent and x-forwaded-for configurable, rename debug path to raw
This commit is contained in:
@@ -71,3 +71,5 @@ http://localhost:8080/debug/https://www.google.com
|
|||||||
| --- | --- | --- |
|
| --- | --- | --- |
|
||||||
| `PORT` | Port to listen on | `8080` |
|
| `PORT` | Port to listen on | `8080` |
|
||||||
| `PREFORK` | Spawn multiple server instances | `false` |
|
| `PREFORK` | Spawn multiple server instances | `false` |
|
||||||
|
| `USER_AGENT` | User agent to emulate | `Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)` |
|
||||||
|
| `X_FORWARDED_FOR` | IP Forwarder address | `66.249.66.1` |
|
||||||
|
|||||||
@@ -10,6 +10,8 @@ services:
|
|||||||
environment:
|
environment:
|
||||||
- PORT=8080
|
- PORT=8080
|
||||||
- PREFORK=true
|
- PREFORK=true
|
||||||
|
- X_FORWARDED_FOR=66.249.66.1
|
||||||
|
- USER_AGENT=Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)
|
||||||
#- GODEBUG=netdns=go+4
|
#- GODEBUG=netdns=go+4
|
||||||
ports:
|
ports:
|
||||||
- "8080:8080"
|
- "8080:8080"
|
||||||
|
|||||||
@@ -23,8 +23,8 @@ func Api(c *fiber.Ctx) error {
|
|||||||
// Fetch the site
|
// Fetch the site
|
||||||
client := &http.Client{}
|
client := &http.Client{}
|
||||||
req, _ := http.NewRequest("GET", u.String(), nil)
|
req, _ := http.NewRequest("GET", u.String(), nil)
|
||||||
req.Header.Set("User-Agent", "Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)")
|
req.Header.Set("User-Agent", UserAgent)
|
||||||
req.Header.Set("X-Forwarded-For", "66.249.66.1")
|
req.Header.Set("X-Forwarded-For", ForwardedFor)
|
||||||
req.Header.Set("Referer", u.String())
|
req.Header.Set("Referer", u.String())
|
||||||
req.Header.Set("Host", u.Host)
|
req.Header.Set("Host", u.Host)
|
||||||
resp, err := client.Do(req)
|
resp, err := client.Do(req)
|
||||||
|
|||||||
@@ -6,12 +6,16 @@ import (
|
|||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
|
"os"
|
||||||
"regexp"
|
"regexp"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/gofiber/fiber/v2"
|
"github.com/gofiber/fiber/v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var UserAgent = getenv("USER_AGENT", "Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)")
|
||||||
|
var ForwardedFor = getenv("X_FORWARDED_FOR", "66.249.66.1")
|
||||||
|
|
||||||
func ProxySite(c *fiber.Ctx) error {
|
func ProxySite(c *fiber.Ctx) error {
|
||||||
// Get the url from the URL
|
// Get the url from the URL
|
||||||
urlQuery := c.Params("*")
|
urlQuery := c.Params("*")
|
||||||
@@ -28,8 +32,8 @@ func ProxySite(c *fiber.Ctx) error {
|
|||||||
// Fetch the site
|
// Fetch the site
|
||||||
client := &http.Client{}
|
client := &http.Client{}
|
||||||
req, _ := http.NewRequest("GET", u.String(), nil)
|
req, _ := http.NewRequest("GET", u.String(), nil)
|
||||||
req.Header.Set("User-Agent", "Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)")
|
req.Header.Set("User-Agent", UserAgent)
|
||||||
req.Header.Set("X-Forwarded-For", "66.249.66.1")
|
req.Header.Set("X-Forwarded-For", ForwardedFor)
|
||||||
req.Header.Set("Referer", u.String())
|
req.Header.Set("Referer", u.String())
|
||||||
req.Header.Set("Host", u.Host)
|
req.Header.Set("Host", u.Host)
|
||||||
resp, err := client.Do(req)
|
resp, err := client.Do(req)
|
||||||
@@ -73,3 +77,11 @@ func rewriteHtml(bodyB []byte, u *url.URL) string {
|
|||||||
|
|
||||||
return body
|
return body
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func getenv(key, fallback string) string {
|
||||||
|
value := os.Getenv(key)
|
||||||
|
if len(value) == 0 {
|
||||||
|
return fallback
|
||||||
|
}
|
||||||
|
return value
|
||||||
|
}
|
||||||
|
|||||||
@@ -23,8 +23,8 @@ func Raw(c *fiber.Ctx) error {
|
|||||||
// Fetch the site
|
// Fetch the site
|
||||||
client := &http.Client{}
|
client := &http.Client{}
|
||||||
req, _ := http.NewRequest("GET", u.String(), nil)
|
req, _ := http.NewRequest("GET", u.String(), nil)
|
||||||
req.Header.Set("User-Agent", "Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)")
|
req.Header.Set("User-Agent", UserAgent)
|
||||||
req.Header.Set("X-Forwarded-For", "66.249.66.1")
|
req.Header.Set("X-Forwarded-For", ForwardedFor)
|
||||||
req.Header.Set("Referer", u.String())
|
req.Header.Set("Referer", u.String())
|
||||||
req.Header.Set("Host", u.Host)
|
req.Header.Set("Host", u.Host)
|
||||||
resp, err := client.Do(req)
|
resp, err := client.Do(req)
|
||||||
Reference in New Issue
Block a user