I am trying to test a proxy that is expecting an SSL handshake immediately, 
even if the client is going to use an SSL CONNECT method. The problem is 
that my Golang and Python test code both seem to have the same flaw. They 
connect to the proxy in the clear, and then issue a CONNECT, but the proxy 
rejects this because it is expecting an SSL handshake.

My code:

// vim: ft=go ts=4 sw=4 et ai:package main
import (
    "net/http"
    "log"
    "io/ioutil"
    "time"
    "crypto/tls"
    "net/url"
    )
var use_proxy = truevar proxy = "https://myproxyip:6881"var req_url = 
"https://google.ca"var n_seconds time.Duration = 15var period = time.Second * 
n_secondsvar n_threads = 50var thread_start_delay time.Duration = 1

func http_fetch(req_url string) {
    tr := http.Transport {
        TLSClientConfig: &tls.Config {
            InsecureSkipVerify: true,
        },
    }
    proxy_url, err := url.Parse(proxy)
    if err != nil {
        log.Fatal(err)
    }
    if use_proxy {
        tr.Proxy = http.ProxyURL(proxy_url)
    }
    client := &http.Client{}
    client.Transport = &tr

    req, err := http.NewRequest("GET", req_url, nil)
    if err != nil {
        log.Fatal(err)
    }
    req.Header.Set("User-Agent", "Mozilla/5.0 (Macintosh; Intel Mac OS X 
10_11_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 
Safari/537.36")

    res, err := client.Do(req)
    if err != nil {
        log.Fatal(err)
    }
    body, err := ioutil.ReadAll(res.Body)
    defer res.Body.Close()
    document := string(body)
    print(document)}


func main() {
    println("main: Starting", n_threads, "threads to hammer", req_url, "every", 
n_seconds, "seconds, ctrl-c to quit...")
    done := make(<-chan bool)
    for i:= 0; i < n_threads; i++ {
        go func(thread_id int) {
            println("thread", thread_id, ": starting periodic_hammer")
            for {
                println("thread", thread_id, ": fetching", req_url)
                http_fetch(req_url)
                println("thread", thread_id, ": done, sleeping for", n_seconds, 
"seconds")
                time.Sleep(period)
            }
        }(i+1)
        println("main: delaying", thread_start_delay, "seconds before starting 
next thread")
        time.Sleep(thread_start_delay * time.Second)
    }
    <-done}

In the end, I had to use a lower-level socket to get this working.

Was I using this incorrectly? Anyone know if the http library is being 
updated to match the latest libcurl, which does support this (Not to 
mention web browsers)?

Thanks,
Mike

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to