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` |
|
||||
| `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:
|
||||
- PORT=8080
|
||||
- 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
|
||||
ports:
|
||||
- "8080:8080"
|
||||
|
||||
@@ -23,8 +23,8 @@ func Api(c *fiber.Ctx) error {
|
||||
// Fetch the site
|
||||
client := &http.Client{}
|
||||
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("X-Forwarded-For", "66.249.66.1")
|
||||
req.Header.Set("User-Agent", UserAgent)
|
||||
req.Header.Set("X-Forwarded-For", ForwardedFor)
|
||||
req.Header.Set("Referer", u.String())
|
||||
req.Header.Set("Host", u.Host)
|
||||
resp, err := client.Do(req)
|
||||
|
||||
@@ -6,12 +6,16 @@ import (
|
||||
"log"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"os"
|
||||
"regexp"
|
||||
"strings"
|
||||
|
||||
"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 {
|
||||
// Get the url from the URL
|
||||
urlQuery := c.Params("*")
|
||||
@@ -28,8 +32,8 @@ func ProxySite(c *fiber.Ctx) error {
|
||||
// Fetch the site
|
||||
client := &http.Client{}
|
||||
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("X-Forwarded-For", "66.249.66.1")
|
||||
req.Header.Set("User-Agent", UserAgent)
|
||||
req.Header.Set("X-Forwarded-For", ForwardedFor)
|
||||
req.Header.Set("Referer", u.String())
|
||||
req.Header.Set("Host", u.Host)
|
||||
resp, err := client.Do(req)
|
||||
@@ -73,3 +77,11 @@ func rewriteHtml(bodyB []byte, u *url.URL) string {
|
||||
|
||||
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
|
||||
client := &http.Client{}
|
||||
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("X-Forwarded-For", "66.249.66.1")
|
||||
req.Header.Set("User-Agent", UserAgent)
|
||||
req.Header.Set("X-Forwarded-For", ForwardedFor)
|
||||
req.Header.Set("Referer", u.String())
|
||||
req.Header.Set("Host", u.Host)
|
||||
resp, err := client.Do(req)
|
||||
Reference in New Issue
Block a user