golang check if javascript is enabled

huangapple go评论83阅读模式
英文:

golang check if javascript is enabled

问题

这是我的实际代码:

package main

import (
	"net/http"
	"net/http/httputil"
	"net/url"
)

const BaseUrl = "http://127.0.01:5000"
const ListeningPort = "80"

func main() {
	// 拦截调用
	http.HandleFunc("/test", Test)

	// 其他所有流量都通过
	http.HandleFunc("/", ProxyFunc)
	http.ListenAndServe(":"+ListeningPort, nil)
}

func ProxyFunc(w http.ResponseWriter, r *http.Request) {
	u, err := url.Parse(BaseUrl)
	if err != nil {
		w.Write([]byte(err.Error()))
		return
	}

	proxy := httputil.NewSingleHostReverseProxy(u)
	proxy.ServeHTTP(w, r)
}

func Test(w http.ResponseWriter, r *http.Request) {
	w.Write([]byte("TEST"))
}

首先,要接受客户端连接,我想检查浏览器是否启用了 JavaScript,我该如何在我的实际代码中实现这一点?

我想使用以下方法进行检查:
https://pastebin.com/ZASFQumf

英文:

this is my actual code :

package main

import (
	"net/http"
	"net/http/httputil"
	"net/url"
)

const BaseUrl = "http://127.0.01:5000"
const ListeningPort = "80"

func main() {
	// intercept call
	http.HandleFunc("/test", Test)

	// all other traffic pass on
	http.HandleFunc("/", ProxyFunc)
	http.ListenAndServe(":"+ListeningPort, nil)
}

func ProxyFunc(w http.ResponseWriter, r *http.Request) {
	u, err := url.Parse(BaseUrl)
	if err != nil {
		w.Write([]byte(err.Error()))
		return
	}

	proxy := httputil.NewSingleHostReverseProxy(u)
	proxy.ServeHTTP(w, r)
}

func Test(w http.ResponseWriter, r *http.Request) {
	w.Write([]byte("TEST"))
}

first to accept client connexion, i want to check if browser have enabled javascript, how i can do this in my actual code ?

i want check with this method :
https://pastebin.com/ZASFQumf

答案1

得分: 1

在Golang中做这个是不可能的,因为它是一种服务器端语言。我甚至认为用JavaScript也不可能实现。

这不是你可以通过头部信息添加/设置/获取的东西。

你正在尝试检查特定于浏览器的标志。

你可能能够找到用于管理Chrome标志或Firefox标志等的第三方库。那是你最好的选择。

英文:

It is not possible to do that in Golang since it is a server side language. I don't even think it is possible with JavaScript.

It is not something you can add/set/get from the headers.

What you are trying to do is check browser specific flags.

You might be able to find third party libraries used to manage Chrome flags or Firefox flags etc. That is your best option.

huangapple
  • 本文由 发表于 2017年9月19日 06:02:19
  • 转载请务必保留本文链接:https://go.coder-hub.com/46288812.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定