Golang Gorilla Websocket with Web Proxy
<p>I'm working on a POC using Gorilla/Websocket to communicate, through a Web Proxy, with the Websocket Check Website "echo.websocket.org".</p>

<p>I'm using the free online Proxy "hide.me/en/" for testing.</p>

<p>When I simply try to communicate with "echo.websocket.org" (Server side), my client-site Websocket POC reach the response.</p>

<p>But when i try to add the Proxy gesture, everything goes wrong :(</p>

<p>Here is a sample of my code :</p>

<pre><code>package main

import (
    "flag"
    "log"
    "net/url"
    "os"
    "os/signal"
    "time"

    "github.com/gorilla/websocket"
    "net/http"
)

var addrWebsocket = flag.String("addrWebsocket", "echo.websocket.org", "http service address")

func main() {
    flag.Parse()
    log.SetFlags(0)

    interrupt := make(chan os.Signal, 1)
    signal.Notify(interrupt, os.Interrupt)

    //Initialize the WebSocket URL and the Path to follow
    uWS := url.URL{Scheme: "wss", Host: *addrWebsocket}

    //Initialize the Proxy URL and the Path to follow
    uProxy, _ := url.Parse("https://hide.me/en/proxy")

    //Set the Dialer (especially the proxy)
    dialer := websocket.Dialer{
        Proxy: http.ProxyURL(uProxy),
    }
    //dialer := websocket.DefaultDialer ==&gt; with this default dialer, it works !

    c, _, err := dialer.Dial(uWS.String(), nil) // ==&gt; With the proxy config, it fails here !
    defer c.Close()

    done := make(chan struct{})

    go func() {
        defer c.Close()
        defer close(done)
        for {
            _, message, err := c.ReadMessage()
            if err != nil {
                log.Println("read:", err)
                return
            }
            log.Printf("recv: %s", message)
        }
    }()

    ticker := time.NewTicker(time.Second)
    defer ticker.Stop()

    for {
        select {
        case t := &lt;-ticker.C:
            err := c.WriteMessage(websocket.TextMessage, []byte(t.String()))
            if err != nil {
                log.Println("write:", err)
                return
            }
        case &lt;-interrupt:
            log.Println("interrupt")
            err := c.WriteMessage(websocket.CloseMessage, websocket.FormatCloseMessage(websocket.CloseNormalClosure, ""))
            if err != nil {
                log.Println("write close:", err)
                return
            }
                select {
                case &lt;-done:
                case &lt;-time.After(time.Second):
                }
            c.Close()
            return
        }
    }
}
</code></pre>

<p>I'm a very beginner in Go so don't hesitate to correct me if my code un not clear and clean.</p>

<p>Thanks for your help !</p>