From 219b5f8ece7b536d4e20f68f2e846f74a8546ade Mon Sep 17 00:00:00 2001 From: Shivam Rathore Date: Wed, 24 Jun 2020 01:03:15 +0530 Subject: [PATCH] notice for safe use and licensing changes (#16) --- README.md | 5 ++++- helper.go | 2 +- license.go | 28 ++++++++++++++++++++++++++++ main.go | 2 +- 4 files changed, 34 insertions(+), 3 deletions(-) create mode 100644 license.go diff --git a/README.md b/README.md index f053e01..8fc7136 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,7 @@ +> Note: This repository and project is for educational and testing purposes only, any illegal or bad use of project or its hosted service `https://non-cors.herokuapp.com` is solely the responsibility of the users using it. Me or the contributors has nothing to do with that. + +> Also, the hosted service https://non-cors.herokuapp.com has been disabled for now, for safety. Sorry for any inconvenience. + # bypass-cors >a proxy server to bypass CORS (Cross-Origin Resource Sharing) enabled servers @@ -37,4 +41,3 @@ Please make your changes in a specific branch and request to pull into master! I ### License The application, its design and its code all are licensed under the [MIT license.](https://github.com/Shivam010/bypass-cors/blob/master/LICENSE) - \ No newline at end of file diff --git a/helper.go b/helper.go index ef4ea6d..9272945 100644 --- a/helper.go +++ b/helper.go @@ -20,7 +20,7 @@ type Valuer interface { func Return(w http.ResponseWriter, res Valuer) { fmt.Printf("Served with: %d-%v \n", res.StatusCode(), http.StatusText(res.StatusCode())) - w.Header().Set("Content-Type", "application/json; charset=utf-8") + //w.Header().Set("Content-Type", "application/json; charset=utf-8") w.WriteHeader(res.StatusCode()) _, _ = fmt.Fprintln(w, res.Value()) } diff --git a/license.go b/license.go new file mode 100644 index 0000000..00e71a0 --- /dev/null +++ b/license.go @@ -0,0 +1,28 @@ +package main + +import ( + "net/http" + "strings" +) + +const ( + licenseKey = "license" + licenseLen = len(licenseKey) + licenseUrl = "https://github.com/Shivam010/bypass-cors/blob/master/LICENSE" +) + +func License(h http.Handler) http.Handler { + return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + w.Header().Add(licenseKey, licenseUrl) + r.Header.Add(licenseKey, licenseUrl) + path := strings.ToLower(r.URL.Path) + // redirect to license if URL path is "/license*" + if len(path) > licenseLen && path[1:licenseLen+1] == licenseKey { + http.Redirect(w, r, licenseUrl, http.StatusPermanentRedirect) + return + } + h.ServeHTTP(w, r) + w.Header().Add(licenseKey, licenseUrl) + r.Header.Add(licenseKey, licenseUrl) + }) +} diff --git a/main.go b/main.go index 5348c91..b755523 100644 --- a/main.go +++ b/main.go @@ -107,7 +107,7 @@ func main() { fmt.Printf("\nStarting Proxy ByPass-Cors Server at port(:%v)...\n\n", PORT) - if err := http.ListenAndServe(":"+PORT, &handler{}); err != nil { + if err := http.ListenAndServe(":"+PORT, License(&handler{})); err != nil { log.Println("\n\nPanics", err) } }