Quantcast
Channel: Active questions tagged https - Stack Overflow
Viewing all articles
Browse latest Browse all 1501

How to accept *tls.Conn using http package without starting new goroutine by http package? [closed]

$
0
0

When I typically create a http server in Go, I do:

http.ListenAndServeTLS("https://localhost:8999", "key.pem", "pub.pem", nil)

But under the hood that method does:

ln, err := net.Listen("tcp", addr)......for {        rw, err := ln.Accept()......}

That is not what I want, but instead I wish to:

...listen, err := net.Listen("tcp", "localhost:8999")  if err != nil {    return  }  pair, err := tls.LoadX509KeyPair("pub.pem", "key.pem")  if err != nil {    return  }go func(){for {  // Read tcp conn  l, err := listen.Accept()  if err != nil {    return  }  // Do something, filter etcgo func() {  tlsC := tls.Server(l, &tls.Config{    ClientAuth:         tls.RequestClientCert,    Certificates:       []tls.Certificate{pair},    InsecureSkipVerify: true,  })  err := tlsC.Handshake()  if err != nil {    return  }  // Do something, filter etc  // I wish to read HTTP request from tlsC here, but without creating yet another goroutine (as http.Serve does)}()}}()...

So I only want http package to read existing connection and parse it, NOT start listening again on net.Listener.

The whole idea of the code is to being able to filter client connection on each stage (tcp, tls, http) and filter itself being some kind of map[], which elements can be called at any time during connection establishing


Viewing all articles
Browse latest Browse all 1501

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>