Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

net/http: issue with wildcard listening in net.http #6808

Closed
gopherbot opened this issue Nov 21, 2013 · 3 comments
Closed

net/http: issue with wildcard listening in net.http #6808

gopherbot opened this issue Nov 21, 2013 · 3 comments

Comments

@gopherbot
Copy link

by pavel.odintsov:

Hello!

I have troubles with wildcard listening on machine with IPv4 and IPv6 both. I need
listen only on IPv4 interfaces.


What steps will reproduce the problem?
If possible, include a link to a program on play.golang.org.
1.  http://play.golang.org./p/WOPvpx3UqT

What is the expected output?
tcp        0      0 0.0.0.0:8443                     :::*                        LISTEN 
    89622/./vzapi       

What do you see instead?
My applications listen both protocols:
netstat -lnpt|grep 8443
tcp        0      0 :::8443                     :::*                        LISTEN     
89622/./vzapi       


Which compiler are you using (5g, 6g, 8g, gccgo)?
go build

Which operating system are you using?
cat /etc/issue
CentOS release 6.4 (Final)
Kernel \r on an \m

Which version are you using?  (run 'go version')
go version
go version go1.1.2 linux/amd64

Please provide any additional information below.
ifconfig 
eth0      Link encap:Ethernet  HWaddr 00:1B:21:B8:7F:52  
          inet addr:176.9.59.50  Bcast:176.9.xxx.xx  Mask:255.255.255.255
          inet6 addr: 2a01:xxx:150:9222::2/64 Scope:Global
          inet6 addr: fe80::21b:21ff:feb8:7f52/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:12578573 errors:0 dropped:32 overruns:0 frame:0
          TX packets:8448379 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:14217230345 (13.2 GiB)  TX bytes:2232820668 (2.0 GiB)

lo        Link encap:Local Loopback  
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:16436  Metric:1
          RX packets:23058 errors:0 dropped:0 overruns:0 frame:0
          TX packets:23058 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0 
          RX bytes:1850865 (1.7 MiB)  TX bytes:1850865 (1.7 MiB)

venet0    Link encap:UNSPEC  HWaddr 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00  
          inet6 addr: fe80::1/128 Scope:Link
          UP BROADCAST POINTOPOINT RUNNING NOARP  MTU:1500  Metric:1
          RX packets:5764178 errors:0 dropped:0 overruns:0 frame:0
          TX packets:8052839 errors:0 dropped:15 overruns:0 carrier:0
          collisions:0 txqueuelen:0 
          RX bytes:1890923604 (1.7 GiB)  TX bytes:8033500011 (7.4 GiB)
@mikioh
Copy link
Contributor

mikioh commented Nov 22, 2013

Comment 1:

You can inject your favorite net.Listener into http stuff. For example,
package main
import (
        "fmt"
        "html"
        "log"
        "net"
        "net/http"
)
func main() {
        ln, err := net.Listen("tcp4", "0.0.0.0:8080")
        if err != nil {
                log.Fatal(err)
        }
        http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
                fmt.Fprintf(w, "Hello, %q", html.EscapeString(r.URL.Path))
        })
        if err := http.Serve(ln, nil); err != nil {
                log.Fatal(err)
        }
}

Status changed to Retracted.

@gopherbot
Copy link
Author

Comment 2 by pavel.odintsov:

Hello!
Thank you for answer!
Unfortunately injecting custom listener into ListenAndServeTLS method leads to copy &
paste about ~35 lines of code from http.go.

@bradfitz
Copy link
Contributor

Comment 3:

ListenAndServeTLS is just an example of code you should copy/paste when you have special
needs.  I've copy/pasted it a number of times and tweaked the config for what I need.  I
think that's okay.

@golang golang locked and limited conversation to collaborators Jun 25, 2016
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants