{"action":"created","issue":{"url":"https://api.github.com/repos/elazarl/goproxy/issues/107","labels_url":"https://api.github.com/repos/elazarl/goproxy/issues/107/labels{/name}","comments_url":"https://api.github.com/repos/elazarl/goproxy/issues/107/comments","events_url":"https://api.github.com/repos/elazarl/goproxy/issues/107/events","html_url":"https://github.com/elazarl/goproxy/issues/107","id":81019466,"number":107,"title":"Catch HTTPS Connect","user":{"login":"amlwwalker","id":2920180,"avatar_url":"https://avatars.githubusercontent.com/u/2920180?v=3","gravatar_id":"","url":"https://api.github.com/users/amlwwalker","html_url":"https://github.com/amlwwalker","followers_url":"https://api.github.com/users/amlwwalker/followers","following_url":"https://api.github.com/users/amlwwalker/following{/other_user}","gists_url":"https://api.github.com/users/amlwwalker/gists{/gist_id}","starred_url":"https://api.github.com/users/amlwwalker/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/amlwwalker/subscriptions","organizations_url":"https://api.github.com/users/amlwwalker/orgs","repos_url":"https://api.github.com/users/amlwwalker/repos","events_url":"https://api.github.com/users/amlwwalker/events{/privacy}","received_events_url":"https://api.github.com/users/amlwwalker/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2015-05-26T15:44:12Z","updated_at":"2015-05-26T19:56:02Z","closed_at":null,"body":"So I can catch the HTTPS Connect, and I started looking at doing this with abourget's fork, however I cant work out how to kill the request and send a response if its over 443.\r\nI think I need to make a custom `ConnectAction` \r\nSo:\r\n```\r\n\t\tproxy.OnRequest().HandleConnectFunc(func(host string, ctx *goproxy.ProxyCtx) (*goproxy.ConnectAction, string) {\r\n\t\t\tlog.Println(\"connecting: \", ctx.Req.URL.Host)\r\n\t\treturn goproxy.OkConnect, host\r\n\t})\r\n```\r\n\r\nNo I want to stop the connection to the server and just respond to the client with some HTML, i.e a `&http.Response` but that doesnt seem to be built into the `HandleConnectFunc` as an option.\r\n\r\nIs this possible, or am I missing a point?\r\n\r\nAll I want to do is catch the connect, if the Host contains HTTPS/443, then stop the connect and respond with an HTTP response.\r\n\r\nEDIT: Hmmm, I can edit the request but I think once HTTPS happens, then thats that????\r\n\r\nIf I change the request to be over 80, rather than 443, it still seems to successfully manage the TLS handshake. I expected it to get passed to my proxy.OnResponse function that handles HTTP responses...\r\n\r\n```\r\n\t\tproxy.OnRequest().HandleConnectFunc(func(host string, ctx *goproxy.ProxyCtx) (*goproxy.ConnectAction, string) {\r\n\t\t\tlog.Println(\"connecting: \", ctx.Req.URL.Host)\r\n\t\t\tif strings.Contains(ctx.Req.URL.Host, \":443\") {\r\n\t\t\t\tlog.Println(\"yup 443\")\r\n\t\t\t\tctx.Req.URL.Host = strings.Replace(ctx.Req.URL.Host, \"443\", \"80\", -1)\r\n\t\t\t\tlog.Println(\"HOST: \", ctx.Req.URL)\r\n\t\t\t}\r\n\r\n\t\treturn goproxy.OkConnect, host\r\n\t})\r\n```\r\n\r\nEDIT AGAIN:\r\n\r\nIs there such thing as a CONNECT response from the server? I am forcing all properties of ctx that have :443 over to :80 which results in:\r\n![image](https://cloud.githubusercontent.com/assets/2920180/7818360/24b6dee2-03d3-11e5-874c-75c7b497ae56.png)\r\n\r\nThats almost good ;)\r\nI can stop the HTTPS connection occuring but I cant force a new HTML page to the client. Is that even possible?"},"comment":{"url":"https://api.github.com/repos/elazarl/goproxy/issues/comments/105647686","html_url":"https://github.com/elazarl/goproxy/issues/107#issuecomment-105647686","issue_url":"https://api.github.com/repos/elazarl/goproxy/issues/107","id":105647686,"user":{"login":"mzimmerman","id":2413139,"avatar_url":"https://avatars.githubusercontent.com/u/2413139?v=3","gravatar_id":"","url":"https://api.github.com/users/mzimmerman","html_url":"https://github.com/mzimmerman","followers_url":"https://api.github.com/users/mzimmerman/followers","following_url":"https://api.github.com/users/mzimmerman/following{/other_user}","gists_url":"https://api.github.com/users/mzimmerman/gists{/gist_id}","starred_url":"https://api.github.com/users/mzimmerman/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mzimmerman/subscriptions","organizations_url":"https://api.github.com/users/mzimmerman/orgs","repos_url":"https://api.github.com/users/mzimmerman/repos","events_url":"https://api.github.com/users/mzimmerman/events{/privacy}","received_events_url":"https://api.github.com/users/mzimmerman/received_events","type":"User","site_admin":false},"created_at":"2015-05-26T19:56:02Z","updated_at":"2015-05-26T19:56:02Z","body":"No, you cannot do that.\r\n\r\nYour browser is expecting the https protocol.  You can't just talk http.\r\n\r\nInstead, because of security rules of certificates and how TLS works, you have to act like the destination that they're trying to go to.  You have to do that from a CA that is trusted by the browser.  Then and only then will the browser accept your TLS handshake and let you then deliver your HTML through https.\r\n\r\nSee [whitelistproxy] (https://github.com/mzimmerman/whitelistproxy) for an example of how to do this using goproxy."}}