1
0
mirror of https://github.com/golang/go synced 2024-10-04 13:21:22 -06:00
Commit Graph

340 Commits

Author SHA1 Message Date
Mikio Hara
087d5c08f8 net: enable unixpacket tests on openbsd
Change-Id: I0e1519d429a295faa70013687d6faf2f5ce0be24
Reviewed-on: https://go-review.googlesource.com/9713
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2015-05-06 00:31:58 +00:00
Brad Fitzpatrick
c661cb01f7 net/http: don't send implicit Content-Length if Transfer-Encoding is set
Fixes #9987

Change-Id: Ibebd105a2bcdc1741f3b41aa78cb986f3f518b53
Reviewed-on: https://go-review.googlesource.com/9638
Reviewed-by: Andrew Gerrand <adg@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
2015-05-06 00:10:12 +00:00
Mikio Hara
055ecb7be5 net: fix inconsistent errors
These a series of changes fix inconsistent errors on the package net
APIs. Now almost all the APIs return OpError as a common error type
except Lookup, Resolve and Parse APIs. The Lookup, Resolve and Parse
APIs return more specific errors such as DNSError, AddrError or
ParseError.

An OpError may contain nested error information. For example, Dial may
return an OpError containing a DNSError, AddrError, unexposed type/value
or other package's type/value like the following:
	OpError{/* dial info */, Err: &DNSError{}}
	OpError{/* dial info */, Err: &AddrError{}}
	OpError{/* dial info */, Err: <unexposed type or value>}
	OpError{/* dial info */, Err: <other package's type or value>}

and Read and Write may return an OpError containing other OpError when
an application uses io.Copy or similar:
	OpError{/* for io.Reader */, Err: &OpError{/* for io.Writer */}}

When an endpoint is created for connection-oriented byte-stream
protocols, Read may return an io.EOF when the connection is closed by
remote endpoint.

Fixes #4856.

A series of changes:
- net: fix inconsistent error values on Dial, Listen partially
  https://go.googlesource.com/go/+/89b7c66d0d14462fd7893be4290bdfe5f9063ae1
- net: fix inconsistent error values on Read
  https://go.googlesource.com/go/+/ec1144423f45e010c72363fe59291d43214b6e31
- net: fix inconsistent error values on Write
  https://go.googlesource.com/go/+/11b5f98bf0d5eb8854f735cc332c912725070214
- net: fix inconsistent error values on Close
  https://go.googlesource.com/go/+/310db63c5bc121e7bfccb494c01a6b91a257e7fc
- net: fix inconsistent error values on Accept
  https://go.googlesource.com/go/+/4540e162b1aefda8157372764ad3d290a414ef1d
- net: fix inconsistent error values on File
  https://go.googlesource.com/go/+/885111365ba0a74421059bfbd18f4c57c1e70332
- net: fix inconsistent error values on setters
  https://go.googlesource.com/go/+/2173a27903897c481b0a0daf3ca3e0a0685701db
- net: fix inconsistent error values on Interface
  https://go.googlesource.com/go/+/456cf0f22c93e1a6654980f4a48a564555f6c8a2
- net: fix inconsistent error values on Lookup
  https://go.googlesource.com/go/+/0fc582e87942b2e52bed751b6c56660ba99e9a7d
- net: add Source field to OpError
  https://go.googlesource.com/go/+/afd2d2b6df3ebfe99faf347030f15adfdf422fa0

Change-Id: Id678e369088dc9fbe9073cfe7ff8a8754a57d61f
Reviewed-on: https://go-review.googlesource.com/9236
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2015-05-05 09:40:07 +00:00
Mikio Hara
2708f19600 net: add missing ReadFrom, WriteTo deadline tests
Change-Id: If84edfaec361ca2fbb75707c4ad30e4ce64f7013
Reviewed-on: https://go-review.googlesource.com/9664
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2015-05-05 08:54:28 +00:00
Brad Fitzpatrick
c723230e4a net/http: fix scheduling race resulting in flaky test
The test was measuring something, assuming other goroutines had
already scheduled.

Fixes #10427

Change-Id: I2a4d3906f9d4b5ea44b57d972e303bbe2b0b1cde
Reviewed-on: https://go-review.googlesource.com/9561
Reviewed-by: David Crawshaw <crawshaw@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
2015-05-01 21:41:03 +00:00
Brad Fitzpatrick
125ed11c0a net/http: document ServeFile and FileServer index.html redirect behavior
Fixes #9876

Change-Id: I97a354fde827dfccc9e373fadea2e37d094439b0
Reviewed-on: https://go-review.googlesource.com/9538
Reviewed-by: Rob Pike <r@golang.org>
2015-04-30 20:42:58 +00:00
Alex A Skinner
f390135733 net: make go DNS use localhost if resolv.conf is missing or empty
Per resolv.conf man page, "If this file does not exist, only the name
server on the local machine will be queried."

This behavior also occurs if file is present but unreadable,
or if no nameservers are listed.

Fixes #10566

Change-Id: Id5716da0eae534d5ebfafea111bbc657f302e307
Reviewed-on: https://go-review.googlesource.com/9380
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2015-04-30 18:19:00 +00:00
Brad Fitzpatrick
ae080c1aec net/http: handle "close" amongst multiple Connection tokens
Fixes #8840

Change-Id: I194d0248734c15336f91a6bcf57ffcc9c0a3a435
Reviewed-on: https://go-review.googlesource.com/9434
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2015-04-29 23:52:43 +00:00
Mikio Hara
98e0556231 net: deflake timeout, deadline tests
This change deflakes timeout, deadline tests, especially fixes socket
and goroutine leaks. Also adds a few missing tests that use features
introduced after go1 release.

Change-Id: Ibf73a4859f8d4a0ee494ca2fd180cbce72a7a2c7
Reviewed-on: https://go-review.googlesource.com/9464
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2015-04-29 23:37:21 +00:00
Mikio Hara
2385f692e8 net: consolidate listener test files
This change merges unicast_posix_test.go and multicast_test.go into
listen_test.go before deflaking tests for Listen functions.

No code changes.

Change-Id: Ic4cd6531b95dfb5b6e6e254241692eca61a71e94
Reviewed-on: https://go-review.googlesource.com/9460
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2015-04-29 23:04:39 +00:00
Mikio Hara
4f38ef811f net: add missing Close tests
This change adds missing CloseRead test and Close tests on Conn,
Listener and PacketConn with various networks.

Change-Id: Iadf99eaf526a323f853d203edc7c8d0577f67972
Reviewed-on: https://go-review.googlesource.com/9469
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2015-04-29 23:01:45 +00:00
Peter Waldschmidt
632778c3a3 net/http: Don't set Content-Length: -1 when responding to a POST
Fixes an issue where Response.Write writes out a Content-Length: -1
header when the corresponding Request is a POST or PUT and the
ContentLength was not previously set.

This was encountered when using httputil.DumpResponse
to write out the response from a server that responded to a PUT
request with no Content-Length header. The dumped output is
thus invalid.

Change-Id: I52c6ae8ef3443f1f9de92aeee9f9581dabb05991
Reviewed-on: https://go-review.googlesource.com/9496
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
2015-04-29 22:58:37 +00:00
Mikio Hara
afd2d2b6df net: add Source field to OpError
Not only by network, transport-layer intermediaries but by
virtualization stuff in a node, it is hard to identify the root cause of
weird faults without information of packet flows after disaster
happened.

This change adds Source field to OpError to be able to represent a
5-tuple of internet transport protocols for helping dealing with
complicated systems.

Also clarifies the usage of Source and Addr fields.

Updates #4856.

Change-Id: I96a523fe391ed14406bfb21604c461d4aac2fa19
Reviewed-on: https://go-review.googlesource.com/9231
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2015-04-29 22:37:30 +00:00
tnt
bfb077e0ee net: allow a dns TXT record to contain more than one <character-string>
RFC 1035 3.3.14 allows a TXT record to contain one or more <character-string>s.
The current implementation returns a "no such host" error if there is more
than one <character-string> in the TXT record.

Fixes #10482

Change-Id: I0ded258005e6b7ba45f687fecd10afa2b321bb77
Reviewed-on: https://go-review.googlesource.com/8966
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
2015-04-29 21:48:48 +00:00
Mikio Hara
a0cff2989a net: remove dead code in Write
Also, please be informed that the Write method on both connected and
unconnected-mode sockets may return a positive number of bytes written
with timeout or use of closed network connection error.

Change-Id: I2e2e6192e29cef4e9389eb0422c605c6d12e6a3c
Reviewed-on: https://go-review.googlesource.com/9466
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2015-04-29 04:40:59 +00:00
Mikio Hara
edac5d9144 net: rename dialgoogle_test.go to external_test.go
In the followup changes, tests that require external facilities such as
DNS servers and RRs will move into external_test.go.

Change-Id: Ib460b0c51961159830357652dbf5430e1ba01514
Reviewed-on: https://go-review.googlesource.com/9461
Reviewed-by: Dave Cheney <dave@cheney.net>
2015-04-29 02:24:27 +00:00
Brad Fitzpatrick
339cf9807d net/http: documentation updates
Fixes #10366 (how to set custom headers)
Fixes #9836 (PATCH in PostForm)
Fixes #9276 (generating a server-side Request for testing)
Update #8991 (clarify Response.Write for now; export ReverseProxy's copy later?)

Change-Id: I95a11bf3bb3eeeeb72775b6ebfbc761641addc35
Reviewed-on: https://go-review.googlesource.com/9410
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2015-04-28 21:58:58 +00:00
Brad Fitzpatrick
5ed44e9d4d net/http: test and document suppressing implicit Content-Type response header
No code changes.

Fixes #8992

Change-Id: I10c8340a4f8e3e7add9b3ac5aa0a1e8d8aa49f40
Reviewed-on: https://go-review.googlesource.com/9412
Reviewed-by: David Crawshaw <crawshaw@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
2015-04-28 20:49:08 +00:00
Mikio Hara
9bef5cfb9b net: don't miss testing server teardowns when test fails early
Change-Id: I9fa678e43b4ae3970323cac474b5f86d4d933997
Reviewed-on: https://go-review.googlesource.com/9382
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2015-04-28 00:01:33 +00:00
Brad Fitzpatrick
4a0ba7aa17 net: use Go's DNS resolver when system configuration permits
If the machine's network configuration files (resolv.conf,
nsswitch.conf) don't have any unsupported options, prefer Go's DNS
resolver, which doesn't have the cgo & thread over.

It means users can have more than 500 DNS requests outstanding (our
current limit for cgo lookups) and not have one blocked thread per
outstanding request.

Discussed in thread https://groups.google.com/d/msg/golang-dev/2ZUi792oztM/Q0rg_DkF5HMJ

Change-Id: I3f685d70aff6b47bec30b63e9fba674b20507f95
Reviewed-on: https://go-review.googlesource.com/8945
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
2015-04-23 02:48:43 +00:00
Daniel Morsing
723f86537c net/http: fix race between dialing and canceling
In the brief window between getConn and persistConn.roundTrip,
a cancel could end up going missing.

Fix by making it possible to inspect if a cancel function was cleared
and checking if we were canceled before entering roundTrip.

Fixes #10511

Change-Id: If6513e63fbc2edb703e36d6356ccc95a1dc33144
Reviewed-on: https://go-review.googlesource.com/9181
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2015-04-22 12:23:55 +00:00
Brad Fitzpatrick
5fa2d9915f net/http: make ServeContent errors return more specific HTTP status codes
Previously all errors were 404 errors, even if the real error had
nothing to do with a file being non-existent.

Fixes #10283

Change-Id: I5b08b471a9064c347510cfcf8557373704eef7c0
Reviewed-on: https://go-review.googlesource.com/9200
Reviewed-by: Daniel Morsing <daniel.morsing@gmail.com>
2015-04-22 10:35:44 +00:00
Brad Fitzpatrick
58c1c011a6 net/http: fix rare Transport readLoop goroutine leak
There used to be a small window where if a server declared it would do
a keep-alive connection but then actually closed the connection before
the roundTrip goroutine scheduled after being sent a response from the
readLoop goroutine, then the readLoop goroutine would loop around and
block forever reading from a channel because the numExpectedResponses
accounting was done too late.

Fixes #10457

Change-Id: Icbae937ffe83c792c295b7f4fb929c6a24a4f759
Reviewed-on: https://go-review.googlesource.com/9169
Reviewed-by: Daniel Morsing <daniel.morsing@gmail.com>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
2015-04-22 10:29:22 +00:00
Mikio Hara
15648d2e77 net: replace server tests
This change replaces server tests with new ones that require features
introduced after go1 release, such as runtime-integrated network poller,
Dialer, etc.

Change-Id: Icf1f94f08f33caacd499cfccbe74cda8d05eed30
Reviewed-on: https://go-review.googlesource.com/9195
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2015-04-22 00:29:40 +00:00
Mikio Hara
03eb132684 net: deflake zero byte IO tests on datagram
This change deflakes zero byte read/write tests on datagram sockets, and
enables them by default.

Change-Id: I52f1a76f8ff379d90f40a07bb352fae9343ea41a
Reviewed-on: https://go-review.googlesource.com/9194
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2015-04-22 00:13:37 +00:00
Mikio Hara
275755401d net: fix WriteTo on Plan 9
This change excludes internal UDP header size from a result of number of
bytes written on WriteTo.

Change-Id: I847d57f7f195657b6f14efdf1b4cfab13d4490dd
Reviewed-on: https://go-review.googlesource.com/9196
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Reviewed-by: David du Colombier <0intro@gmail.com>
2015-04-22 00:11:30 +00:00
Mikio Hara
0f6a3ba420 net: fix possible nil pointer dereference on ReadFrom for windows
Fixes #10516.

Change-Id: Ia93f53d4e752bbcca6112bc75f6c3dbe30b90dac
Reviewed-on: https://go-review.googlesource.com/9192
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2015-04-21 06:34:44 +00:00
Mikio Hara
0fc582e879 net: fix inconsistent error values on Lookup
This change fixes inconsistent error values on
Lookup{Addr,CNAME,Host,IP.MX,NS,Port,SRV,TXT}.

Updates #4856.

Change-Id: I059bc8ffb96ee74dff8a8c4e8e6ae3e4a462a7ef
Reviewed-on: https://go-review.googlesource.com/9108
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2015-04-21 05:16:07 +00:00
Mikio Hara
456cf0f22c net: fix inconsistent error values on Interface
This change fixes inconsistent error values on Interfaces,
InterfaceAddrs, InterfaceBy{Index,Name}, and Addrs and MulticastAddrs
methods of Interface.

Updates #4856.

Change-Id: I09e65522a22f45c641792d774ebf7a0081b874ad
Reviewed-on: https://go-review.googlesource.com/9140
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2015-04-21 04:16:14 +00:00
Mikio Hara
2173a27903 net: fix inconsistent error values on setters
This change fixes inconsistent error values on
Set{Deadline,ReadDeadline,WriteDeadline,ReadBuffer,WriteBuffer} for
Conn, Listener and PacketConn, and
Set{KeepAlive,KeepAlivePeriod,Linger,NoDelay} for TCPConn.

Updates #4856.

Change-Id: I34ca5e98f6de72863f85b2527478b20d8d5394dd
Reviewed-on: https://go-review.googlesource.com/9109
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2015-04-21 04:05:59 +00:00
Mikio Hara
885111365b net: fix inconsistent error values on File
This change fixes inconsistent error values on
File{Conn,Listener,PacketConn} and File method of Conn, Listener.

Updates #4856.

Change-Id: I3197b9277bef0e034427e3a44fa77523acaa2520
Reviewed-on: https://go-review.googlesource.com/9101
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2015-04-21 03:37:41 +00:00
Mikio Hara
832c573595 net: add helpers for server testing
Also moves a few server test helpers into mockserver_test.go.

Change-Id: I5a95c9bc6f0c4683751bcca77e26a8586a377466
Reviewed-on: https://go-review.googlesource.com/9106
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2015-04-21 01:00:11 +00:00
Brad Fitzpatrick
b016eba489 net/http: fix Transport data race, double cancel panic, cancel error message
Fixes #9496
Fixes #9946
Fixes #10474
Fixes #10405

Change-Id: I4e65f1706e46499811d9ebf4ad6d83a5dfb2ddaa
Reviewed-on: https://go-review.googlesource.com/8550
Reviewed-by: Daniel Morsing <daniel.morsing@gmail.com>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
2015-04-20 20:34:43 +00:00
Mikio Hara
757f21fd6f net: fix a nit found by vet
Change-Id: Ic965b48bdc0e0ffba9bed5ff6b3d28ff742f8b2d
Reviewed-on: https://go-review.googlesource.com/9100
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2015-04-19 10:45:49 +00:00
Mikio Hara
4540e162b1 net: fix inconsistent error values on Accept
This change fixes inconsistent error values on Accept{,TCP,Unix}.

Updates #4856.

Change-Id: Ie3bb534c19a724cacb3ea3f3656e46c810b2123f
Reviewed-on: https://go-review.googlesource.com/8996
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2015-04-18 03:38:50 +00:00
Mikio Hara
310db63c5b net: fix inconsistent error values on Close
This change fixes inconsistent error values on Close, CloseRead and
CloseWrite.

Updates #4856.

Change-Id: I3c4d46ccd7d6e1a2f52d8e75b512f62c533a368d
Reviewed-on: https://go-review.googlesource.com/8994
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2015-04-18 03:12:04 +00:00
Mikio Hara
11b5f98bf0 net: fix inconsistent error values on Write
This change fixes inconsistent error values on Write,
WriteTo{,UDP,IP,Unix} and WriteMsg{UDP,IP,Unix}.

Updates #4856.

Change-Id: I4208ab6a0650455ad7d70a80a2d6169351d6055f
Reviewed-on: https://go-review.googlesource.com/8993
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2015-04-18 02:44:08 +00:00
Mikio Hara
ec1144423f net: fix inconsistent error values on Read
This change fixes inconsistent error values on Read,
ReadFrom{,UDP,IP,Unix} and ReadMsg{UDP,IP,Unix}.

Updates #4856.

Change-Id: I7de5663094e09be2d78cdb18ce6f1e7ec260888d
Reviewed-on: https://go-review.googlesource.com/8992
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2015-04-18 02:19:46 +00:00
Mikio Hara
d0f3100b47 net: break up TestErrorNil into Test{Dial,Listen,ListenPacket}Error
Change-Id: I7c6c91a0551aacb49e1beb4a39215b93c8c7fcfa
Reviewed-on: https://go-review.googlesource.com/8997
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2015-04-18 01:43:35 +00:00
Mikio Hara
6d3a7e79a4 net: clean up cgo
This change adds a type addrinfoErrno to represent getaddrinfo,
getnameinfo-specific errors, and uses it in cgo-based lookup functions.

Also retags cgo files for clarification and does minor cleanup.

Change-Id: I6db7130ad7bf35bbd4e8839a97759e1364c43828
Reviewed-on: https://go-review.googlesource.com/9020
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2015-04-17 23:19:19 +00:00
Mikio Hara
89b7c66d0d net: fix inconsistent error values on Dial, Listen partially
This change makes TestDialError, TestListenError work without any
external dependency, enables them by default, and removes unnecessary
-run_error_test flag for fixing #4856.

Also fixes inconsistent error values on Dial, Listen partially as a
first stab.

Updates #4856.

Change-Id: Ie10c151ae06759085f352c7db2ca45107a81914f
Reviewed-on: https://go-review.googlesource.com/8903
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2015-04-17 00:42:57 +00:00
Mikio Hara
3185cfbfbb net: rename netFD.proto to netFD.net on Plan 9
In followup changes, we'll move OpError around from the netFD layer to
the Conn layer for fixing #4856. Before doing that, this change makes
netFD of Plan 9 match netFD for POSIX platforms to avoid conflict.

Change-Id: Iea7632716d48722a1758e52effefec964a3a9442
Reviewed-on: https://go-review.googlesource.com/8990
Reviewed-by: David du Colombier <0intro@gmail.com>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2015-04-17 00:09:13 +00:00
David du Colombier
3eadc59b0d net: fix typo in comment
Change-Id: I8b2063e65d3454a694a789c1682dacfe0bea2e19
Reviewed-on: https://go-review.googlesource.com/8965
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2015-04-16 18:45:05 +00:00
Mikio Hara
57bc7a0434 net: fix TestDialGoogle with -ipv6 when CGO_ENABLED=0
Under some dial tests that require external network connectivity, we
must prevent application traffic but must not interfere with control
plane traffic such as DNS message exchange. But test helper function
disableSocketConnect prevents both application and control plane traffic
unconditionally and makes some dial tests with -ipv6 fail when
CGO_ENABLED=0.

This change makes disableSocketConnect take a look at not only address
family but socket type for fixing some dial tests with -ipv6 when
CGO_ENBALED=0.

Change-Id: I32241d9592d31483424bb5e69cb4d56f3fc20312
Reviewed-on: https://go-review.googlesource.com/8743
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2015-04-16 00:44:52 +00:00
Mikio Hara
47515e0116 net: add Listen system call hook for testing
Change-Id: I63053c45081f47ba736720a78d85c31c13767891
Reviewed-on: https://go-review.googlesource.com/8642
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Run-TryBot: Mikio Hara <mikioh.mikioh@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2015-04-15 11:47:49 +00:00
Mikio Hara
130e3f9a32 net/internal/socktest: add hook for Listen, failed system call counters
Change-Id: Icaac9a48a3b9a3c5542235162e21ab8303592965
Reviewed-on: https://go-review.googlesource.com/8641
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2015-04-15 11:03:50 +00:00
Brad Fitzpatrick
47f095501e net: remove old comment
The memory model has been clarified since. This is legal and doesn't
need justification.

Change-Id: I60f9938503f86f52bb568ca1a99ac721ee72cee5
Reviewed-on: https://go-review.googlesource.com/8913
Reviewed-by: Mikio Hara <mikioh.mikioh@gmail.com>
2015-04-14 04:38:20 +00:00
Ian Lance Taylor
63cced7b31 net: document that DNSError.Timeout and Temporary are unreliable
Update #10417.

Change-Id: Ibfbdd05358f696a37217eef160f71b14a468ff86
Reviewed-on: https://go-review.googlesource.com/8788
Reviewed-by: Rob Pike <r@golang.org>
2015-04-13 20:41:50 +00:00
David Crawshaw
c0d48836ec net/http/cgi: skip fork test on darwin/arm64
Just like darwin/arm.

Change-Id: Ib9a32bb0aed5f08b27de11a93aaf273cacdf5779
Reviewed-on: https://go-review.googlesource.com/8819
Reviewed-by: Minux Ma <minux@golang.org>
2015-04-13 11:51:53 +00:00
Brad Fitzpatrick
dc2d64bf81 cmd/go: cache results of HTTP requests done during meta tag discovery
Previously, running

  $ go get -u -v golang.org/x/tools/cmd/godoc

would results in dozens of HTTP requests for

  https://golang.org/x/tools?go-get=1

once per package under x/tools.

Now it caches the results. We still end up doing one HTTP request for
all the packages under x/tools, but this reduces the total number of
HTTP requests in ~half.

This also moves the singleflight package back into an internal
package. singleflight was originally elsewhere as a package, then got
copied into "net" (without its tests). But now that we have internal,
put it in its own package, and restore its test.

Fixes #9249

Change-Id: Ieb5cf04fc4d0a0c188cb957efdc7ea3068c34e3f
Reviewed-on: https://go-review.googlesource.com/8727
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
2015-04-13 07:08:00 +00:00
Paul Marks
a5dec3859a net: make multi-IP resolution more flexible.
Remove the "netaddr" type, which ambiguously represented either one
address, or a list of addresses. Instead, use "addrList" wherever
multiple addresses are supported.

The "first" method returns the first address matching some condition
(e.g. "is it IPv4?"), primarily to support legacy code that can't handle
multiple addresses.

The "partition" method splits an addrList into two categories, as
defined by some strategy function. This is useful for implementing
Happy Eyeballs, and similar two-channel algorithms.

Finally, internetAddrList (formerly resolveInternetAddr) no longer
mangles the ordering defined by getaddrinfo. In the future, this may
be used by a sequential Dial implementation.

Updates #8453, #8455.

Change-Id: I7375f4c34481580ab40e31d33002a4073a0474f3
Reviewed-on: https://go-review.googlesource.com/8360
Reviewed-by: Mikio Hara <mikioh.mikioh@gmail.com>
Run-TryBot: Mikio Hara <mikioh.mikioh@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2015-04-10 09:03:25 +00:00
Daniel Morsing
39377013cb net/http: handle close/response race more gracefully
There was a logical race in Transport.RoundTrip where a roundtrip with
a pending response would race with the channel for the connection
closing. This usually happened for responses with connection: close
and no body.

We handled this race by reading the close channel, setting a timer
for 100ms and if no response was returned before then, we would then
return an error.

This put a lower bound on how fast a connection could fail. We couldn't
fail a request faster than 100ms.

Reordering the channel operations gets rid of the logical race. If
the readLoop causes the connection to be closed, it would have put
its response into the return channel already and we can fetch it with
a non-blocking receive.

Change-Id: Idf09e48d7a0453d7de0120d3055d0ce5893a5428
Reviewed-on: https://go-review.googlesource.com/1787
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2015-04-09 13:46:50 +00:00
Mikio Hara
957255f5ab net/http: don't send IPv6 zone identifier in outbound request, per RFC 6874
When making a request to an IPv6 address with a zone identifier, for
exmaple [fe80::1%en0], RFC 6874 says HTTP clients must remove the zone
identifier "%en0" before writing the request for security reason.

This change removes any IPv6 zone identifer attached to URI in the Host
header field in requests.

Fixes #9544.

Change-Id: I7406bd0aa961d260d96f1f887c2e45854e921452
Reviewed-on: https://go-review.googlesource.com/3111
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2015-04-09 09:26:52 +00:00
Rob Pike
514eb4aa54 net/rpc: document that the type must be exported, not just the methods
Fixes #10379.

Change-Id: Ia4cdda36ed57a06371f9ace7365ce9e215228487
Reviewed-on: https://go-review.googlesource.com/8654
Reviewed-by: Rob Pike <r@golang.org>
2015-04-08 18:34:35 +00:00
Mikio Hara
8e95654ac8 net/url: allow Parse, ParseRequestURI to parse ipv6 zone identifiers in URIs
Using IPv6 link-local addresses to make connections between on-link
nodes is useful for small distributed applications but it requires zone
identifiers to distinguish a correct IP link. It's the same for
transports using URI for destination discovery such as HTTP, WebSocket.

This change allows Parse, ParseRequestURI functions and String method of
URL to parse/return a literal IPv6 address followed by a zone identifier
within a URI as described in RFC 6874.

Fixes #6530.

Change-Id: I2936ea65c1446994770cf2ee2c28a1c73faaa0ca
Reviewed-on: https://go-review.googlesource.com/2431
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2015-04-07 14:24:23 +00:00
Mikio Hara
5a83f06c21 net: deflake dual IP stack tests
This change deflakes TestDialerDualStackFDLeak, TestDialerDualStack,
TestResolve{TCP,UDP,IP}Addr by removing external dependencies.

Fixes #8764.

Change-Id: I5cca0a93776cf05652e0e6a4a4ff4af392ccb885
Reviewed-on: https://go-review.googlesource.com/8485
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2015-04-07 13:32:28 +00:00
Mikio Hara
f077505d9a net: fix tester goroutine leakage in tests
This change tries to stop various tester goroutines at the end of each
scope for avoiding interference between test cases including benchmarks.
Not yet finished completely but enough to land upcoming changes to Dial
functions. The rest will be fixed later.

Change-Id: Ic38b8681a3a2ddbcd69ba3696f24a61d418a0346
Reviewed-on: https://go-review.googlesource.com/8398
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2015-04-07 03:26:03 +00:00
Mikio Hara
be4c38ed34 net: move testHookSetKeepAlive into hook.go
Change-Id: I1f2d4e3b0351a7a47c3a6073833a17dbc0c7b05c
Reviewed-on: https://go-review.googlesource.com/8520
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2015-04-07 03:02:10 +00:00
Mikio Hara
35b3db253c net: add lookup IP hook for testing
This change adds testHookLookIP to enable to inject DNS name to IP
address mappings for Happ{y,yish,ier} Eyeballs dial testing.

Change-Id: I8ac04a594e1e2bd77909528df0552889914a7790
Reviewed-on: https://go-review.googlesource.com/8399
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2015-04-07 02:34:42 +00:00
Igor Dolzhikov
debe12cfcf net/http, math/big, cmd/internal/gc/big: replaced errors.New(fmt.Sprintf(...)) in favour fmt.Errorf()
Change-Id: I38fc0ab84a374cb9be0234e40665d7cea0e76fc1
Reviewed-on: https://go-review.googlesource.com/8402
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2015-04-06 15:40:34 +00:00
Paul Marks
c50a8416c8 net: dialChannel should not treat an expired deadline as noDeadline.
Now, only a zero deadline is interpreted as noDeadline.  Any other time
in the past yields an immediate timeout.

TestConnectDeadlineInThePast already covers this case.  We just need to
un-skip it for plan9, where dialChannel is used.

Change-Id: I995fd1a632c31f8004dac772c3d7c43a2a5853b0
Reviewed-on: https://go-review.googlesource.com/8435
Reviewed-by: Mikio Hara <mikioh.mikioh@gmail.com>
2015-04-06 01:03:31 +00:00
Mikio Hara
21ed40c8cb net: deflake TestDialGoogle, TestResolveDialGoogle
This change makes use of the socktest package instead of the non-thread
safe variable syscall.SocketDisableIPv6 for simulating unreachable
external networks.

Also adds -ipv4 flag, -ipv6 flag already exists, as a control knob for
testing on each of IPv4-only, IPv6-only and dual IP stack kernels.

Fixes #7687.

Change-Id: I82002007fd526e8cf4de207f935e721df049a22f
Reviewed-on: https://go-review.googlesource.com/8390
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2015-04-03 01:50:30 +00:00
Mikio Hara
167562f652 net: deflake TestDialTimeoutFDLeak
This change makes TestDialTimeoutFDLeak work on almost all the supported
platforms.

Updates #4384.

Change-Id: I3608f438003003f9b7cfa17c9e5fe7077700fd60
Reviewed-on: https://go-review.googlesource.com/8392
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2015-04-03 00:48:47 +00:00
Mikio Hara
3a9024b498 net: move init function into net.go
It's a single, package-wide init function specified for the net package.

Change-Id: Id5894d65e1a92297cc16803cc5e4d4eef0b4b099
Reviewed-on: https://go-review.googlesource.com/8391
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2015-04-03 00:23:23 +00:00
Mikio Hara
52c84c34fd net: move test flags into main_test.go
Also updates the comments on test flags.

Change-Id: I8dbd90270e08728ab309ab88a3030e0f8e547175
Reviewed-on: https://go-review.googlesource.com/8394
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2015-04-02 09:07:24 +00:00
Mikio Hara
8b0e38ffb4 net: deflake TestDialTimeout
This change makes TestDialTimeout work on almost all the supported
platforms.

Updates #3016.
Updates #3307.
Updates #3867.
Updates #5380.
Updates #5349.

Change-Id: Iacf0ebea23cdd8f6c0333d70c667a5a5f5eb0ed2
Reviewed-on: https://go-review.googlesource.com/8220
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2015-04-02 01:04:49 +00:00
Mikio Hara
93553dd216 net: fix data race in benchmarks
Fixes #10307.

Change-Id: If70f36a6f1c4e465a47a0bc4d38b318424111106
Reviewed-on: https://go-review.googlesource.com/8330
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2015-04-01 22:02:41 +00:00
Mikio Hara
29d1f3b85c net: add socket system call hooks for testing
This change adds socket system call hooks to existing test cases for
simulating a bit complicated network conditions to help making timeout
and dual IP stack test cases work more properly in followup changes.

Also test cases print debugging information in non-short mode like the
following:

Leaked goroutines:
net.TestWriteTimeout.func2(0xc20802a5a0, 0xc20801d000, 0x1000, 0x1000, 0xc2081d2ae0)
	/go/src/net/timeout_test.go:170 +0x98
created by net.TestWriteTimeout
	/go/src/net/timeout_test.go:173 +0x745
net.runDatagramPacketConnServer(0xc2080730e0, 0x2bd270, 0x3, 0x2c1770, 0xb, 0xc2081d2ba0, 0xc2081d2c00)
	/go/src/net/server_test.go:398 +0x667
created by net.TestTimeoutUDP
	/go/src/net/timeout_test.go:247 +0xc9
	(snip)

Leaked sockets:
3: {Cookie:615726511685632 Err:<nil> SocketErr:0}
5: {Cookie:7934075906097152 Err:<nil> SocketErr:0}

Socket statistical information:
{Family:1 Type:805306370 Protocol:0 Opened:17 Accepted:0 Connected:5 Closed:17}
{Family:2 Type:805306369 Protocol:0 Opened:450 Accepted:234 Connected:279 Closed:636}
{Family:1 Type:805306369 Protocol:0 Opened:11 Accepted:5 Connected:5 Closed:16}
{Family:28 Type:805306369 Protocol:0 Opened:95 Accepted:22 Connected:16 Closed:116}
{Family:2 Type:805306370 Protocol:0 Opened:84 Accepted:0 Connected:34 Closed:83}
{Family:28 Type:805306370 Protocol:0 Opened:52 Accepted:0 Connected:4 Closed:52}

Change-Id: I0e84be59a0699bc31245c78e2249423459b8cdda
Reviewed-on: https://go-review.googlesource.com/6390
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2015-03-31 23:07:42 +00:00
Mikio Hara
7b2b45e544 net: simplify test helpers
This change consolidates test helpers that test platform capabilities.
testNetwork, testAddress and testListenArgs report whether given
ariguments are testable on the current platform configuration to
mitigate to receive weird test results.

Change-Id: Ie1ed568a1f9cc50f3155945ea01562904bc2c389
Reviewed-on: https://go-review.googlesource.com/8076
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2015-03-28 08:21:10 +00:00
Brad Fitzpatrick
8047093e5b net: reenable a previously skipped test
Update #8859

Change-Id: I5b0005b308e83954a495f06d27b7d8d30e813820
Reviewed-on: https://go-review.googlesource.com/8193
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2015-03-27 16:15:56 +00:00
Mikio Hara
4d54f27b35 net/internal/socktest: new package
Package socktest provides utilities for socket testing.

This package allows test cases in the net package to simulate
complicated network conditions such as that a destination address is
resolvable/discoverable but is not routable/reachable at network layer.
Those conditions are required for testing functionality of timeout,
multiple address families.

Change-Id: Idbe32bcc3319b41b0cecac3d058014a93e13288b
Reviewed-on: https://go-review.googlesource.com/6090
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2015-03-25 00:13:46 +00:00
Shenghou Ma
1c26176b67 net/url: fix docs for URL.String
Fixes #10227.

Change-Id: I64d5522e76da5a717e3c4169405e5ef35d6c262e
Signed-off-by: Shenghou Ma <minux@golang.org>
Reviewed-on: https://go-review.googlesource.com/7974
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2015-03-24 23:56:43 +00:00
David Crawshaw
5bf9249eda net/http: enable segfaulting test on darwin/arm
Issue #10043 was resolved by https://golang.org/cl/7072.
This test now passes.

Change-Id: I7bdef63d9ee4edcede23613a14a2ddce14018f34
Reviewed-on: https://go-review.googlesource.com/7931
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2015-03-23 14:27:17 +00:00
Mikio Hara
14082fad9b net: fix TestInterfaces, TestInterfaceAddrs on platforms without loopback interface
Fixes #10214.

Change-Id: If29d26c590eb53d4976e0a6ace0ed33aaf0c3e80
Reviewed-on: https://go-review.googlesource.com/7924
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Reviewed-by: Alex Brainman <alex.brainman@gmail.com>
2015-03-23 10:00:34 +00:00
Brad Fitzpatrick
a0fb8f8cce net/http: ignore the Unix epoch time in ServeContent
ServeContent ignored zero time.Time{} values when generating
Last-Modified response headers and checking If-Modified-Since request
headers. Do the same for a time.Time representing the Unix epoch zero
value, as this is a common bogus value. Callers who really want to
send that value (incredibly unlikely) can add a nanosecond to it and
it will be truncated to second granularity anyway.

Fixes #9842

Change-Id: I69f697bfc4017404a92a34e3fe57e2711c1e299d
Reviewed-on: https://go-review.googlesource.com/7915
Reviewed-by: David Symonds <dsymonds@golang.org>
2015-03-23 02:16:56 +00:00
Quoc-Viet Nguyen
7274b1f6c9 net/http/pprof: Correct body tag in index template
The body tag in the pprof template was misplaced.

Change-Id: Icd7948b358f52df1acc7e033ab27a062990ef977
Reviewed-on: https://go-review.googlesource.com/7795
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2015-03-19 22:45:34 +00:00
Josh Bleecher Snyder
2adc4e8927 all: use "reports whether" in place of "returns true if(f)"
Comment changes only.

Change-Id: I56848814564c4aa0988b451df18bebdfc88d6d94
Reviewed-on: https://go-review.googlesource.com/7721
Reviewed-by: Rob Pike <r@golang.org>
2015-03-18 15:14:06 +00:00
Matt Joiner
4f489f59c2 net/http/pprof: Use relative links to profiles in index html
This allows /debug/pprof/ and descendents to be used through
http.StripPrefix and other path rewriting handlers.

Change-Id: I53673876c107bbfaf430123ead78e6524b42ac21
Reviewed-on: https://go-review.googlesource.com/7351
Reviewed-by: Andrew Gerrand <adg@golang.org>
2015-03-12 01:13:26 +00:00
David Crawshaw
ac080fa6d8 net: skip unixgram tests on darwin/arm
Change-Id: I9d2c84237f7b1c4dc2e53adf249b7518dda81a21
Reviewed-on: https://go-review.googlesource.com/7165
Run-TryBot: David Crawshaw <crawshaw@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
2015-03-09 15:34:32 +00:00
Mikio Hara
bcf43e9565 net: gofmt
Change-Id: Ifcf7b96e67b63a08f410a7ba21e8bf4dd20e7d8e
Reviewed-on: https://go-review.googlesource.com/7122
Reviewed-by: Minux Ma <minux@golang.org>
2015-03-08 22:03:21 +00:00
Andrew Pilloud
f00362b9ec net: LookupHost and Resolve{TCP,UDP,IP}Addr should use zone from getaddrinfo
The unix and windows getaddrinfo calls return a zone with IPv6
addresses. IPv6 link-local addresses returned are only valid on the
given zone. When the zone is dropped, connections to the address
will fail. This patch replaces IP with IPAddr in several internal
resolver functions, and plumbs through the zone.

Change-Id: Ifea891654f586f15b76988464f82e04a42ccff6d
Reviewed-on: https://go-review.googlesource.com/5851
Reviewed-by: Mikio Hara <mikioh.mikioh@gmail.com>
2015-03-08 09:58:11 +00:00
David Crawshaw
5e49bfec92 net: fix darwin/amd64 build
Accidental semantics change in 4c6364a87d.

Change-Id: I0bbfc441662d79af4dbac6f9fc4e3a485adfb924
Reviewed-on: https://go-review.googlesource.com/6831
Reviewed-by: Minux Ma <minux@golang.org>
2015-03-04 22:56:23 +00:00
Shenghou Ma
4c6364a87d net: skip unsupported tests (unix and unixgram) on darwin/arm
Change-Id: Id1927180ecd18b849727225adea05465d36b3973
Reviewed-on: https://go-review.googlesource.com/6210
Reviewed-by: Mikio Hara <mikioh.mikioh@gmail.com>
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2015-03-04 22:12:05 +00:00
David Crawshaw
4f6630de3a net/http: disable segfaulting test on darwin/arm
Issue #10043

Change-Id: I6ce7f303cd96ac575f7a673dd4a459339382d22e
Reviewed-on: https://go-review.googlesource.com/6692
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2015-03-03 23:09:06 +00:00
Mikio Hara
59cc5a197f syscall: fix parsing ipv6 address prefix on dragonfly
This change fixes a missing case that a routing address contains an
invalid address family label but it holds a valid length of address
structure.

Also makes test robust.

Fixes #10041.

Change-Id: I2480ba273929e859896697382d1a75b01a116b98
Reviewed-on: https://go-review.googlesource.com/6391
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2015-03-03 03:27:14 +00:00
Dmitry Vyukov
04a3a74456 net/http/fcgi: fix test
Currently the test fails if run more than once:

$ go test -v -run=TestChildServeCleansUp -cpu=1,1 net/http/fcgi
=== RUN TestChildServeCleansUp
--- PASS: TestChildServeCleansUp (0.00s)
=== RUN TestChildServeCleansUp
fatal error: all goroutines are asleep - deadlock!

The problem is that the writer mutates test input data,
so it is wrong on the second execution.

Change-Id: I4ca54dd2926c6986b2908023ac65e5e65630ed26
Reviewed-on: https://go-review.googlesource.com/6383
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2015-03-02 06:59:29 +00:00
Brad Fitzpatrick
aedee30870 net: deflake TestPacketConn, increase timeout
Tests sometimes failed with:

ok   mime/internal/quotedprintable      0.606s
ok   mime/multipart                     0.819s
--- FAIL: TestPacketConn (0.10s)
    packetconn_test.go:96: PacketConn.ReadFrom failed: WSARecvFrom udp 127.0.0.1:64156: i/o timeout
FAIL
FAIL    net     3.602s
ok      net/http        4.618s
ok      net/http/cgi    0.576s

Theory: 100 ms is too short. Small timer granularity on Wnidows, or an
allocation in the middle causing a GC sometimes?

In any case, increase it to 500 ms.

Change-Id: I48cc4d600eb168db9f85c0fd05335dd630254c3c
Reviewed-on: https://go-review.googlesource.com/4922
Reviewed-by: Alex Brainman <alex.brainman@gmail.com>
2015-03-01 22:55:34 +00:00
Brad Fitzpatrick
cf14e0e333 net: disable TestTCPReadWriteAllocs on dragonfly
Update #8859
Update #10042

Change-Id: Idc7eadb447b73563ce9085e50c2042652442c2d9
Reviewed-on: https://go-review.googlesource.com/6412
Reviewed-by: Minux Ma <minux@golang.org>
2015-03-01 22:32:22 +00:00
Russ Cox
4734464a14 net: disable failing interface tests on dragonfly
(Issue #10041.)

Change-Id: Ia894ab60ac6b09926c684f99aacca79275cbced4
Reviewed-on: https://go-review.googlesource.com/6365
Reviewed-by: Russ Cox <rsc@golang.org>
2015-03-01 00:19:32 +00:00
Josh Bleecher Snyder
b1c0d8a54b net: disable TestTCPReadWriteAllocs on darwin
Having this test fail, as it does reliably for me,
makes working frustrating. Disable it for now,
until we can diagnose the issue.

Update issue #8859.

Change-Id: I9dda30d60793e7a51f48f445c78ccb158068cc25
Reviewed-on: https://go-review.googlesource.com/6381
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2015-02-28 20:43:55 +00:00
David Crawshaw
be7090498b net/http/cgi: skip exec test on darwin/arm
Change-Id: I2fc3cf94b465bf9d7ff8d7bf935b45e334b401e3
Reviewed-on: https://go-review.googlesource.com/6180
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
2015-02-26 22:46:39 +00:00
Mikio Hara
3dd029aa7e net: enable TestTCPReadWriteAllocs in short mode
The change 2096 removed unwanted allocations and a few noises in test
using AllocsPerRun. Now it's safe to enable this canary test on netpoll
hotpaths.

Change-Id: Icdbee813d81c1410a48ea9960d46447042976905
Reviewed-on: https://go-review.googlesource.com/5713
Reviewed-by: Dmitry Vyukov <dvyukov@google.com>
2015-02-24 08:26:56 +00:00
Alexandre Cesaro
828129fdbc net/mail: move RFC 2047 code to internal/mime
The code concerning quoted-printable encoding (RFC 2045) and its
variant for MIME headers (RFC 2047) is currently spread in
mime/multipart and net/mail. It is also not exported.

This commit is the second step to fix that issue. It moves the
RFC 2047 encoding and decoding functions from net/mail to
internal/mime. The exported API is unchanged.

Updates #4943

Change-Id: I5f58aa58e74bbe4ec91b2e9b8c81921338053b00
Reviewed-on: https://go-review.googlesource.com/2101
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2015-02-23 17:46:37 +00:00
Aaron Jacobs
d5630142fd net/http: Removed some unused constants in request.go.
Change-Id: I05cdf357249166a45105703e9317793aa2088844
Reviewed-on: https://go-review.googlesource.com/5560
Reviewed-by: Andrew Gerrand <adg@golang.org>
2015-02-22 23:52:44 +00:00
Mikio Hara
69275eef5e net, syscall: more accurate parsers for routing messages on BSD variants
This changes fixes two issues with regard to handling routing messages
as follows:
- Misparsing on platforms (such as FreeBSD) supporting multiple
  architectures in the same kernel (kern.supported_archs="amd64 i386")
- Misparsing with unimplemented messages such as route, interface
  address state notifications

To fix those issues, this change implements all the required socket
address parsers, adds a processor architecture identifying function to
FreeBSD and tests.

Fixes #9707.
Fixes #8203.

Change-Id: I7ed7b4a0b6f10f54b29edc681a2f35603f2d8d45
Reviewed-on: https://go-review.googlesource.com/4330
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2015-02-20 04:33:28 +00:00
Alex Sergeyev
eaf8e8cbe5 net/http/cgi: fix REMOTE_ADDR, REMOTE_HOST, add REMOTE_PORT
Env vars were incorrectly copying whole value of http.RemoteAddr
to REMOTE_ADDR and REMOTE_HOST. They contained IP:port pair which
instead should only have IP (RFC 3875, other sources).

Module also was not setting REMOTE_PORT variable which become de-facto
standard for passing TCP client port to CGI scripts (Apache mod_cgi,
IIS, and probably others)

Fixes #9861

Change-Id: Ia73e664c48539e3c7db4997d09d957884e98d8a5
Reviewed-on: https://go-review.googlesource.com/4933
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2015-02-18 19:56:50 +00:00
Yasuhiro Matsumoto
d866cd6817 all: fix typo in doc
Change-Id: I89fdda2914030dfea3183a8b4681dd4b33489729
Reviewed-on: https://go-review.googlesource.com/4996
Reviewed-by: Minux Ma <minux@golang.org>
2015-02-17 04:37:18 +00:00
Mikio Hara
f43a8dea92 net: disable WriteMsgUDP tests on nacl, windows (fix build)
Change-Id: I695b89ec2b63233d94c49c4a40a57b50350ec67c
Reviewed-on: https://go-review.googlesource.com/4350
TryBot: Mikio Hara <mikioh.mikioh@gmail.com>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2015-02-10 23:21:40 +00:00
Mikio Hara
a9a6757c64 net: update documentation for WriteMsgUDP
Change-Id: I69f24887601e491d6d722bfeb2952d927df8ad80
Reviewed-on: https://go-review.googlesource.com/4351
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2015-02-10 22:27:17 +00:00
Nicolas S. Dade
263405ea4a net: permit WriteMsgUDP to connected UDP sockets
The sanity checks at the beginning of WriteMsgUDP were too
strict, and did not allow a case sendmsg(2) suppports: sending
to a connected UDP socket.

This fixes the sanity checks. Either the socket is unconnected,
and a destination addresses is required (what all existing callers
must have been doing), or the socket is connected and an explicit
destination address must not be used.

Fixes #9807

Change-Id: I08d4ec3c2bf830335c402acfc0680c841cfcec71
Reviewed-on: https://go-review.googlesource.com/3951
Reviewed-by: Mikio Hara <mikioh.mikioh@gmail.com>
2015-02-10 08:00:39 +00:00
Rajat Goel
d34ee29a52 net/http: fix test to check that requests to 'localhost' are not proxied
I think the test was meant to test requests to 'localhost:80' instead
of 'localhost:80:80'. It passes even with 'localhost:80:80' because
net.SplitHostPort fails inside useProxy. Please comment if you want to
leave old 'localhost:80' is the list too to check old code path.

Change-Id: Ic4cd21901563449e3d4e2f4c8caf723f4ca15bac
u
Reviewed-on: https://go-review.googlesource.com/4293
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2015-02-10 03:01:30 +00:00
mattn
ea22a08fd4 net: re-implement Interfaces and InterfaceAddrs for IPNet, IPv6 on Windows
Fixes #5395

Change-Id: I4322bc8a974d04d9bae6b48c71c5d32d9252973c
Reviewed-on: https://go-review.googlesource.com/3024
Reviewed-by: Alex Brainman <alex.brainman@gmail.com>
2015-02-10 00:44:05 +00:00
Dmitry Vyukov
6d06d4862d net: don't allocate dialer closure if we won't use it
When we use dialMulti we also allocate dialSingle closure for no reason.

Change-Id: I074282a9d6e2c2a1063ab311a1b95e10fe65219f
Reviewed-on: https://go-review.googlesource.com/4119
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2015-02-09 08:30:40 +00:00
Brad Fitzpatrick
46bff7558a net/smtp: document SendMail more
Fixes #9776

Change-Id: I53741fd970244bbfa6874adcb4f1e3d0e7de386b
Reviewed-on: https://go-review.googlesource.com/4162
Reviewed-by: Andrew Gerrand <adg@golang.org>
2015-02-07 22:23:10 +00:00
Shenghou Ma
7e43aee301 net: document that user shouldn't modify returned Addr
Ideally, those methods should return a copy of the Addr, but
due to the Go 1 API guarantee, we cannot make that change now:
there might exist client code that uses the returned Addr as
map index and thus relies on the fact that different invocation
of the method returns the same pointer. Changing this behavior
will lead to hidden behaviour change in those programs.

Update #9654.

Change-Id: Iad4235f2ed7789b3a3c8e0993b9718cf0534ea2b
Reviewed-on: https://go-review.googlesource.com/3851
Reviewed-by: Mikio Hara <mikioh.mikioh@gmail.com>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2015-02-06 19:21:40 +00:00
Péter Surányi
9b6ccb1323 all: don't refer to code.google.com/p/go{,-wiki}/
Only documentation / comment changes. Update references to
point to golang.org permalinks or go.googlesource.com/go.
References in historical release notes under doc are left as is.

Change-Id: Icfc14e4998723e2c2d48f9877a91c5abef6794ea
Reviewed-on: https://go-review.googlesource.com/4060
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2015-02-06 14:41:47 +00:00
Erik Aigner
017182258a net/http: Fix typo in MaxBytesReader comment
Change-Id: Ida064ff422d077d508ef94f52fc813daa6277a99
Reviewed-on: https://go-review.googlesource.com/3933
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2015-02-05 16:38:10 +00:00
Mikio Hara
c768a84b38 net: remove the dregs of old built-in poll server
We don't need placeholders for the old built-in poll server any more.

Change-Id: I3a510aec6a30bc2ac97676c400177cdfe557b8dc
Reviewed-on: https://go-review.googlesource.com/3863
Reviewed-by: Dmitry Vyukov <dvyukov@google.com>
2015-02-04 10:16:38 +00:00
Mikio Hara
5ab3823c6b net: update TDDO
The issue #8432 has been marked as an issue for golang.org/x/net.

Change-Id: Ia39abd99b685c820ea6169ee6505b16028e7e77f
Reviewed-on: https://go-review.googlesource.com/3836
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2015-02-04 04:57:32 +00:00
Blake Gentry
38dcc8cd88 net/http: remove unused switchReader type
Change-Id: Ic8a01d06ffc6c80beaf6dee9e7242dcbb7425e71
Reviewed-on: https://go-review.googlesource.com/3822
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2015-02-03 23:24:36 +00:00
Mikio Hara
826fa06189 net: case insensitivity of DNS labels in built-in stub resolver
This change adds support for case insensitivity of DNS labels to
built-in DNS stub resolver as described in RFC 4343.

Fixes #9215.

Change-Id: Ia752fe71866a3bfa3ea08371985b799d419ddea3
Reviewed-on: https://go-review.googlesource.com/3685
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2015-02-03 10:29:50 +00:00
Erik Aigner
77067c1697 net/http: remove redundant strings.TrimPrefix
We already checked for the prefix with strings.HasPrefix

Change-Id: I33852fd19ffa92aa33b75b94b4bb505f4043a54a
Reviewed-on: https://go-review.googlesource.com/3691
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2015-02-03 09:58:37 +00:00
David Crawshaw
09114fb359 net: failed not faild
Change-Id: Iea4221186325783db2029b07af1409015ddeda99
Reviewed-on: https://go-review.googlesource.com/3695
Reviewed-by: Dave Cheney <dave@cheney.net>
2015-02-02 11:36:04 +00:00
Mikio Hara
e16ed28707 net: remove full stack test cases for IPConn
A few packages that handle net.IPConn in golang.org/x/net sub repository
already implement full stack test cases with more coverage than the net
package. There is no need to keep duplicate code around here.

This change removes full stack test cases for IPConn that require
knowing how to speak with each of protocol stack implementation of
supported platforms.

Change-Id: I871119a9746fc6a2b997b69cfd733463558f5816
Reviewed-on: https://go-review.googlesource.com/3404
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2015-01-29 10:21:44 +00:00
Mikio Hara
5e279ddd01 net: remove solaris tag from cgo
For now solaris port does not support cgo. Moreover, its system calls
and library interfaces are different from BSD.

Change-Id: Idb4fed889973368b35d38b361b23581abacfdeab
Reviewed-on: https://go-review.googlesource.com/3306
Reviewed-by: Aram Hăvărneanu <aram@mgk.ro>
2015-01-29 10:07:21 +00:00
Brad Fitzpatrick
f3857f5748 net/http: close HTTP response bodies in benchmark
This should fix the race builders.

Change-Id: I9c9e7393d5e29d64ab797e346b34b1fa1dfe6d96
Reviewed-on: https://go-review.googlesource.com/3441
Reviewed-by: Dmitry Vyukov <dvyukov@google.com>
2015-01-28 19:40:59 +00:00
Dmitry Vyukov
690db9c89f net/http/pprof: add tracing support
net/http/pprof part of tracing functionality:
https://docs.google.com/document/u/1/d/1FP5apqzBgr7ahCCgFO-yoVhk4YZrNIDNf9RybngBc14/pub
Full change:
https://codereview.appspot.com/146920043

Change-Id: I9092028fcbd5e8f97a56f2c155889ccdfb494afb
Reviewed-on: https://go-review.googlesource.com/1453
Reviewed-by: Russ Cox <rsc@golang.org>
2015-01-28 19:40:09 +00:00
Dmitry Vyukov
8bc30e0733 net/http: fix goroutine leak in benchmark
Race builders report goroutine leaks after addition of this benchmark:
http://build.golang.org/log/18e47f4cbc18ee8db125e1f1157573dd1e333c41
Close idle connection in default transport.

Change-Id: I86ff7b2e0972ed47c5ebcb9fce19e7f39d3ff530
Reviewed-on: https://go-review.googlesource.com/3412
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2015-01-28 13:42:12 +00:00
Mikio Hara
bed884e8b9 net: update test cases for network interface API
This change extends existing test case to Windows for helping to fix
golang.org/issue/5395.

Change-Id: Iff077fa98ede511981df513f48d84c19375b3e04
Reviewed-on: https://go-review.googlesource.com/3304
Reviewed-by: Alex Brainman <alex.brainman@gmail.com>
2015-01-28 03:39:20 +00:00
Dmitry Vyukov
a66aa77c2d net/http: add client benchmark
BenchmarkClient is intended for profiling
the client without the HTTP server code.
The server code runs in a subprocess.

Change-Id: I9aa128604d0d4e94dc5c0372dc86f962282ed6e8
Reviewed-on: https://go-review.googlesource.com/3164
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2015-01-27 19:10:58 +00:00
Martin Möhrmann
494b4ce2a7 net: simplify itoa conversions
Rename itod to uitoa to have consistent naming with other itoa functions.
Reduce redundant code by calling uitoa from itoa.
Reduce buffer to maximally needed size for conversion of 64bit integers.
Adjust calls to itoa functions in package net to use new name for itod.
Avoid calls to itoa if uitoa suffices.

Change-Id: I79deaede4d4b0c076a99a4f4dd6f644ba1daec53
Reviewed-on: https://go-review.googlesource.com/2212
Reviewed-by: Mikio Hara <mikioh.mikioh@gmail.com>
2015-01-22 13:01:28 +00:00
Evan Kroske
68b78b8abd net/http/fcgi: Fix resource leaks
Close the pipe for the body of a request when it is aborted and close
all pipes when child.serve terminates.

Fixes #6934

Change-Id: I1c5e7d2116e1ff106f11a1ef8e99bf70cf04162a
Reviewed-on: https://go-review.googlesource.com/1923
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2015-01-19 22:54:54 +00:00
Jongmin Kim
fd880f8d26 net/http: remove unused test type
Change-Id: Ia8d4459a39425583027f00410fe17b9686b768db
Reviewed-on: https://go-review.googlesource.com/3026
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2015-01-19 15:56:49 +00:00
Mikio Hara
3b5be4522a net: more accurate parsing of IPv4 header on IPConn
As shown in #9395, inaccurate implementation would be a cause of parsing
IPv4 header twice and corrupted upper-layer message issues.

Change-Id: Ia1a042e7ca58ee4fcb38fe9ec753c2ab100592ca
Reviewed-on: https://go-review.googlesource.com/3001
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2015-01-19 03:20:59 +00:00
Martin Möhrmann
c2c0bf77ef net/http/cgi: correctly handle pathnames for cygwin perl on windows
Cygwin perl uses unix pathnames in windows. Include cygwin perl in the
list of special cases for unix pathname handling in test.cgi.

Change-Id: I30445a9cc79d62d022ecc232c35aa5015b7418dc
Reviewed-on: https://go-review.googlesource.com/2973
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Reviewed-by: Alex Brainman <alex.brainman@gmail.com>
2015-01-17 22:51:55 +00:00
Ian Lance Taylor
fdb855420b net: fix some typos in comments
Change-Id: I1bf1ab930a5c258f5fcc85ca3037692c71bf3cb2
Reviewed-on: https://go-review.googlesource.com/2870
Reviewed-by: Mikio Hara <mikioh.mikioh@gmail.com>
Reviewed-by: Minux Ma <minux@golang.org>
2015-01-15 22:59:04 +00:00
Brad Fitzpatrick
3ab4b68bc1 net/http: deflake TestResponseWriterWriteStringAllocs, test interface instead
Skip the allocation testing (which was only used as a signal for
whether the interface was implemented by ResponseWriter), and just
test for it directly.

Fixes #9575

Change-Id: Ie230f1d21b104537d5647e9c900a81509d692469
Reviewed-on: https://go-review.googlesource.com/2720
Reviewed-by: Alex Brainman <alex.brainman@gmail.com>
2015-01-13 01:38:10 +00:00
David du Colombier
4e03bbb1ad net/http/httputil: skip TestReverseProxyCancellation on Plan 9
Update #9554

Change-Id: I7de2a7d585d56b84ab975565042ed997e6124e08
Reviewed-on: https://go-review.googlesource.com/2613
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2015-01-10 00:23:04 +00:00
Peter Waller
ececbe89d4 net/http/httputil: ReverseProxy request cancellation
If an inbound connection is closed, cancel the outbound http request.

This is particularly useful if the outbound request may consume resources
unnecessarily until it is cancelled.

Fixes #8406

Change-Id: I738c4489186ce342f7e21d0ea3f529722c5b443a
Signed-off-by: Peter Waller <p@pwaller.net>
Reviewed-on: https://go-review.googlesource.com/2320
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2015-01-09 19:44:13 +00:00
Brad Fitzpatrick
ee2ecc4552 bufio: add Reader.Discard
Reader.Discard is the complement to Peek. It discards the next n bytes
of input.

We already have Reader.Buffered to see how many bytes of data are
sitting available in memory, and Reader.Peek to get that that buffer
directly. But once you're done with the Peek'd data, you can't get rid
of it, other than Reading it.
Both Read and io.CopyN(ioutil.Discard, bufReader, N) are relatively
slow. People instead resort to multiple blind ReadByte calls, just to
advance the internal b.r variable.

I've wanted this previously, several people have asked for it in the
past on golang-nuts/dev, and somebody just asked me for it again in a
private email. There are a few places in the standard library we'd use
it too.

Change-Id: I85dfad47704a58bd42f6867adbc9e4e1792bc3b0
Reviewed-on: https://go-review.googlesource.com/2260
Reviewed-by: Russ Cox <rsc@golang.org>
2015-01-07 06:37:57 +00:00
Mikio Hara
2958860ee8 net: add test cases for parsing ipv4-mapped ipv6 address
This CL adds missing ipv4-mapped ipv6 address test cases to TestParseIP.

Change-Id: I3144d2a88d409bd515cf52f8711d407bfa81ed68
Reviewed-on: https://go-review.googlesource.com/2205
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2015-01-04 10:28:00 +00:00
Mikio Hara
a877e81caa net: don't return io.EOF on reading data from datagram, raw sockets on windows
Preventing returning io.EOF on non-connection oriented sockets is
already applied to Unix variants. This CL applies it to Windows.

Update #4856.

Change-Id: I82071d40f617e2962d0540b9d1d6a10ea4cdb2ec
Reviewed-on: https://go-review.googlesource.com/2203
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Alex Brainman <alex.brainman@gmail.com>
2015-01-01 05:21:32 +00:00
Mikio Hara
a456801615 net: remove redundant test case for lookupIP with threadLimit
There is no reason to have the redundant test case TestDNSThreadLimt
because TestLookupIPDeadline does cover what we need to test with
-dnsflood flag and more.

Also this CL moves TestLookupIPDeadline into lookup_test.go to avoid
abusing to control the order of test case execution by using file name.

Change-Id: Ib417d7d3411c59d9352c03c996704d584368dc62
Reviewed-on: https://go-review.googlesource.com/2204
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2015-01-01 05:20:16 +00:00
Brad Fitzpatrick
4b96409aac net/http: support for setting trailers from a server Handler
We already had client support for trailers, but no way for a server to
set them short of hijacking the connection.

Fixes #7759

Change-Id: Ic83976437739ec6c1acad5f209ed45e501dbb93a
Reviewed-on: https://go-review.googlesource.com/2157
Reviewed-by: Andrew Gerrand <adg@golang.org>
2014-12-30 04:27:17 +00:00
Brad Fitzpatrick
26d5573949 net/smtp: add TLSConnectionState accessor
Fixes #9451

Change-Id: I0540e398b30c10779ac9d5a67a01d44bb6054a92
Reviewed-on: https://go-review.googlesource.com/2151
Reviewed-by: David Symonds <dsymonds@golang.org>
2014-12-28 21:35:58 +00:00
Guobiao Mei
ddef2d27fe net/http: use t.Fatalf rather than t.Fatal in cookie_test.go
Change-Id: I60bbb7deb7462d1ca884677b4f86bd54b20b3f35
Reviewed-on: https://go-review.googlesource.com/2140
Reviewed-by: Minux Ma <minux@golang.org>
2014-12-27 23:52:37 +00:00
George Shammas
3ffc9756d1 net/http/cgi: Correctly pass down the REMOTE_PORT value for CGI requests.
Currently when we get a CGI or FCGI request, the remote port of the client
is hard coded to zero, despite nearly every webserver passing down the
REMOTE_PORT variable.

This was likely originally excluded because the CGI RFC (rfc3875) does not
mention anything about the remote port of the client. However every webserver
tested does pass REMOTE_PORT down. This includes Apache 2.2, Apache 2.4,
nginx and lighttpd.

Fixes #8351

Change-Id: I4c6366cb39f0ccc05e038bd31d85f93b76e8d0c8
Reviewed-on: https://go-review.googlesource.com/1750
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2014-12-23 01:33:26 +00:00
Jed Denlea
474ce6903b net/http: Fix Range off-by-one error
Given a file of size N, a request for "Range: bytes=N-*" should
return a 416 [1].  Currently, it returns a 206 and a body of 0
bytes, with the illegal Content-Range of "bytes N-(N-1)/N" [2].

[1]: RFC 7233, sec 2.1: "If a valid byte-range-set includes at least one
byte-range-spec with a first-byte-pos that is less than the current
length of the representation, [...]".  sec 3.1: "If all of the
preconditions are true, the server supports the Range header field for
the target resource, and the specified range(s) are invalid or
unsatisfiable, the server SHOULD send a 416 (Range Not Satisfiable)
response."

[2]: RFC 7233, sec 4.2: "A Content-Range field value is invalid if it
contains a byte-range-resp that has a last-byte-pos value less than its
first-byte-pos value, [...]"

Fixes #8988

Change-Id: If3e1134e7815f5d361efea01873b29aafe3de817
Reviewed-on: https://go-review.googlesource.com/1862
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2014-12-20 23:42:44 +00:00
Brad Fitzpatrick
01b2560068 net/http: make Client.Timeout return net.Error errors indicating timeout
Co-hacking with Dave Cheney.

Fixes #9405

Change-Id: I14fc3b6a47dcdb5e514e93d062b804bb24e89f47
Reviewed-on: https://go-review.googlesource.com/1875
Reviewed-by: Dave Cheney <dave@cheney.net>
2014-12-20 05:00:24 +00:00
Brad Fitzpatrick
8f36655346 net/http/httputil: don't use DisableKeepAlives in DumpRequestOut, fix build
I broke the build in https://golang.org/change/207950a when I made
http.Transport send "Connection: close" request headers when
DisableKeepAlives was set true because I didn't run all the tests
before submitting.

httputil.DumpRequestOut used Transport to get its output, and used it
with DisableKeepAlives, so this changed the output.

Rather than updating golden data in our tests (because surely others
depend on the exact bytes from these in their tests), switch to not
using DisableKeepAlives in DumpRequestOut instead, so the output is
the same as before.

Change-Id: I9fad190be8032e55872e6947802055a6d65244df
Reviewed-on: https://go-review.googlesource.com/1632
Reviewed-by: Andrew Gerrand <adg@golang.org>
2014-12-16 06:58:43 +00:00
Brad Fitzpatrick
207950ad51 net/http: make Transport send 'Connection: close' when DisableKeepAlives
No bug was open, but I found an old email to myself to investigate
when I suspected this was happening.

Change-Id: Icedefec6f15a000eaabb2693b0640b3b6c8bf82c
Reviewed-on: https://go-review.googlesource.com/1578
Reviewed-by: Andrew Gerrand <adg@golang.org>
2014-12-16 06:16:28 +00:00
Brad Fitzpatrick
3185f8620c net/textproto: turn an ancient DoS BUG annotation into a comment
Actually fixing this "bug" would be weird, since io.LimitReader already
does what we need, as demonstrated by net/http's use.

Thanks to @davidfstr for pointing this out.

Change-Id: If707bcc698d1666a369b39ddfa9770685fbe3879
Reviewed-on: https://go-review.googlesource.com/1579
Reviewed-by: Rob Pike <r@golang.org>
2014-12-16 04:17:30 +00:00
Brad Fitzpatrick
8476d4cf29 net/http: document Response.Body Read+Close interaction with keep-alive
Fixes #5645

Change-Id: Ifb46d6faf7ac838792920f6fe00912947478e761
Reviewed-on: https://go-review.googlesource.com/1531
Reviewed-by: David Symonds <dsymonds@golang.org>
2014-12-13 10:18:18 +00:00
Brad Fitzpatrick
0e4ee0c9bf net/http: fix timer leak in Transport when using ResponseHeaderTimeout
Fixes #9104

Change-Id: Ide5ac70215d73278e6910f5b9c7687ad7734c0be
Reviewed-on: https://go-review.googlesource.com/1530
Reviewed-by: David Symonds <dsymonds@golang.org>
2014-12-13 07:48:24 +00:00
Brad Fitzpatrick
e67a39ed08 net/http: avoid some allocations in DetectContentType
Change-Id: I64985f8de7ca09e63208e8c949a5d4f4fc09073f
Reviewed-on: https://go-review.googlesource.com/1230
Reviewed-by: David Symonds <dsymonds@golang.org>
2014-12-09 02:00:09 +00:00
Nigel Tao
891abf9cc7 net/http: add comment to clarify whether Dir is '/' or '\'.
LGTM=bradfitz
R=bradfitz, alex.brainman
CC=golang-codereviews
https://golang.org/cl/168600044
2014-11-14 11:43:01 +11:00
Brad Fitzpatrick
38ea0ae05f net/url: add example of using URL.Opaque with http.Request
Per private thread soliciting help. I realized part of this is
documented in several places, but we lacked a unifying
example.

LGTM=rsc
R=golang-codereviews
CC=adg, golang-codereviews, iant, rsc
https://golang.org/cl/171620043
2014-11-12 14:27:27 -08:00
Andrew Gerrand
7f0be1f781 all: use golang.org/x/... import paths
LGTM=rsc, r
R=r, rsc
CC=golang-codereview, golang-codereviews
https://golang.org/cl/168050043
2014-11-10 09:15:57 +11:00
Brad Fitzpatrick
cf105e2fa0 net/http: fix benchmark goroutine leak
New detection because of net/http now using TestMain.

Fixes #9033

LGTM=iant
R=golang-codereviews, iant
CC=adg, golang-codereviews, rsc
https://golang.org/cl/170210043
2014-11-08 15:13:28 -03:00
Ian Lance Taylor
8985c091e4 net/http: add missing newline in list of leaked goroutines
LGTM=bradfitz
R=bradfitz
CC=golang-codereviews
https://golang.org/cl/168860044
2014-10-31 10:20:36 -07:00
Mikio Hara
21a9141ab3 net: add test for lookupIPDeadline
Just to confirm the fix, by typing the follwing:
go test -run=TestLookupIPDeadline -dnsflood or
go test -run=TestLookupIPDeadline -dnsflood -tags netgo

Update #8602

LGTM=iant
R=iant
CC=golang-codereviews
https://golang.org/cl/166740043
2014-10-28 16:20:49 +09:00
Ian Lance Taylor
77595e462b net: if a DNS lookup times out, forget that it is in flight
Before this CL, if the system resolver does a very slow DNS
lookup for a particular host, all subsequent requests for that
host will hang waiting for that lookup to complete.  That is
more or less expected when Dial is called with no deadline.
When Dial has a deadline, though, we can accumulate a large
number of goroutines waiting for that slow DNS lookup.  Try to
avoid this problem by restarting the DNS lookup when it is
redone after a deadline is passed.

This CL also avoids creating an extra goroutine purely to
handle the deadline.

No test because we would have to simulate a slow DNS lookup
followed by a fast DNS lookup.

Fixes #8602.

LGTM=bradfitz
R=bradfitz, mikioh.mikioh
CC=golang-codereviews, r, rsc
https://golang.org/cl/154610044
2014-10-27 08:46:18 -07:00
Russ Cox
c5943c668b net/http/pprof: run GC for /debug/pprof/heap?gc=1
We force runtime.GC before WriteHeapProfile with -test.heapprofile.
Make it possible to do the same with the HTTP interface.

Some servers only run a GC every few minutes.
On such servers, the heap profile will be a few minutes stale,
which may be too old to be useful.

Requested by private mail.

LGTM=dvyukov
R=dvyukov
CC=golang-codereviews
https://golang.org/cl/161990043
2014-10-24 10:58:13 -04:00
Brad Fitzpatrick
42c3130780 net/http: don't send implicit gzip Accept-Encoding on Range requests
The http package by default adds "Accept-Encoding: gzip" to outgoing
requests, unless it's a bad idea, or the user requested otherwise.
Only when the http package adds its own implicit Accept-Encoding header
does the http package also transparently un-gzip the response.

If the user requested part of a document (e.g. bytes 40 to 50), it appears
that Github/Varnish send:
        range(gzip(content), 40, 50)

And not:
        gzip(range(content, 40, 50))

The RFC 2616 set of replacements (with the purpose of
clarifying ambiguities since 1999) has an RFC about Range
requests (http://tools.ietf.org/html/rfc7233) but does not
mention the interaction with encodings.

Regardless of whether range(gzip(content)) or gzip(range(content)) is
correct, this change prevents the Go package from asking for gzip
in requests if we're also asking for Range, avoiding the issue.
If the user cared, they can do it themselves. But Go transparently
un-gzipping a fragment of gzip is never useful.

Fixes #8923

LGTM=adg
R=adg
CC=golang-codereviews
https://golang.org/cl/155420044
2014-10-15 17:51:30 +02:00
Brad Fitzpatrick
9d51cd0fee net/http: don't reuse a server connection after any Write errors
Fixes #8534

LGTM=adg
R=adg
CC=golang-codereviews
https://golang.org/cl/149340044
2014-10-15 17:51:12 +02:00
Rob Pike
968153d063 net/rpc: fix mutex comment
Fixes #8086.

LGTM=bradfitz
R=golang-codereviews, bradfitz
CC=golang-codereviews
https://golang.org/cl/153420044
2014-10-13 10:27:51 -07:00
Alex Brainman
c689abd56c net: link skipped TestReadFromUDP to the issue
LGTM=minux
R=bradfitz, minux
CC=golang-codereviews
https://golang.org/cl/154220043
2014-10-10 13:12:32 +11:00
Alex Brainman
eeb2211a5b net: skip new TestReadFromUDP on nacl and plan9 (fixes build)
TBR=0intro
R=golang-codereviews
CC=golang-codereviews
https://golang.org/cl/157820043
2014-10-10 09:46:41 +11:00
Ron Hashimoto
3114bd6f97 net: disable SIO_UDP_CONNRESET behavior on windows.
Fixes #5834.

LGTM=alex.brainman
R=golang-codereviews, bradfitz, alex.brainman, mikioh.mikioh, in60jp, iant
CC=golang-codereviews
https://golang.org/cl/149510043
2014-10-10 09:21:32 +11:00
David du Colombier
9be9861c91 net/rpc: fix build
LGTM=adg
R=golang-codereviews, adg
CC=golang-codereviews
https://golang.org/cl/151620043
2014-10-09 11:21:21 +02:00
David du Colombier
e6295210b9 net/rpc: skip TestGobError on Plan 9
LGTM=bradfitz
R=rsc, bradfitz
CC=aram, golang-codereviews
https://golang.org/cl/154140043
2014-10-09 11:12:03 +02:00
Russ Cox
3492ee5d3a net/rpc: listen on localhost, let kernel pick port
This avoids a pop-up box on OS X and it avoids
a test failure if something is using 5555.
I apologize for not noticing this during the review.

TBR=r
CC=golang-codereviews
https://golang.org/cl/152320044
2014-10-07 23:08:07 -04:00
Rob Pike
6ee36a9151 net/rpc: add test for issue 7689 (gob error should cause EOF)
Helpfully supplied by tommi.virtanen in issue 8173.

LGTM=rsc
R=golang-codereviews, rsc
CC=golang-codereviews
https://golang.org/cl/151370043
2014-10-07 10:52:16 -07:00
Jens Frederich
f739b77508 net/http: fix authentication info leakage in Referer header (potential security risk)
http.Client calls URL.String() to fill in the Referer header, which may
contain authentication info. This patch removes authentication info from
the Referer header without introducing any API changes.

A new test for net/http is also provided.

This is the polished version of Alberto García Hierro's
https://golang.org/cl/9766046/

It should handle https Referer right.

Fixes #8417

LGTM=bradfitz
R=golang-codereviews, gobot, bradfitz, mikioh.mikioh
CC=golang-codereviews
https://golang.org/cl/151430043
2014-10-07 07:13:42 -07:00
Russ Cox
5b829cca12 net/url: document result of String
Fixes #8742.

LGTM=bradfitz
R=golang-codereviews
CC=adg, bradfitz, golang-codereviews, iant
https://golang.org/cl/155910043
2014-10-06 15:49:07 -04:00
Russ Cox
83001ffaaf net: disable TestDualStackUDPListener in short mode
This test is flaky, just like TestDualStackTCPListener.
That one was disabled. Disable this one too.

Update #5001

LGTM=bradfitz
R=rlh, bradfitz
CC=golang-codereviews
https://golang.org/cl/154950043
2014-10-06 13:09:14 -04:00
Rob Pike
cd5b785efe net/rpc: shut down connection if gob has error
The nicest solution would be to buffer the message and only write
it if it encodes correctly, but that adds considerable memory and
CPU overhead for a very rare condition. Instead, we just shut
down the connection if this happens.
Fixes #7689.

LGTM=rsc
R=rsc
CC=golang-codereviews
https://golang.org/cl/146670043
2014-10-01 13:18:44 -07:00
Brad Fitzpatrick
4a532c664d net/http/httputil: ensure DumpRequestOut dumps all of Body
Bodies larger than 8KB (the default bufio reader size) weren't
being dumped.  Force a read of the body so they're teed into
the response buffer.

Thanks to Steven Hartland for identifying the problem.

Fixes #8089

LGTM=r
R=golang-codereviews, r
CC=adg, golang-codereviews
https://golang.org/cl/144650044
2014-09-30 12:09:34 -07:00
Brad Fitzpatrick
f13cec9f57 net/http: make Transport.CloseIdleConnections also close pending dials
See comment 4 of https://code.google.com/p/go/issues/detail?id=8483#c4:

"So if a user creates a http.Client, issues a bunch of
requests and then wants to shutdown it and all opened connections;
what is she intended to do? The report suggests that just waiting for
all pending requests and calling CloseIdleConnections won't do, as
there can be new racing connections. Obviously she can't do what
you've done in the test, as it uses the unexported function.  If this
happens periodically, it can lead to serious resource leaks (the
transport is also preserved alive).  Am I missing something?"

This CL tracks the user's intention to close all idle
connections (CloseIdleConnections sets it true; and making a
new request sets it false). If a pending dial finishes and
nobody wants it, before it's retained for a future caller, the
"wantIdle" bool is checked and it's closed if the user has
called CloseIdleConnections without a later call to make a new
request.

Fixes #8483

LGTM=adg
R=golang-codereviews, dvyukov, adg
CC=golang-codereviews, rsc
https://golang.org/cl/148970043
2014-09-29 18:16:15 -07:00
James Tucker
2da734189d net/http: enable Transfer-Encoding: identity without Content-Length for HTTP 1.1.
Use case is SSE recommended configuration: http://www.w3.org/TR/eventsource/#notes
Removes a TODO.

LGTM=bradfitz
R=golang-codereviews, bradfitz, tommi.virtanen
CC=golang-codereviews
https://golang.org/cl/100000044
2014-09-29 13:53:42 -07:00
Brad Fitzpatrick
705c1f5cd4 net/http: clarify Request.FormValue docs
Fixes #8067

LGTM=r
R=r
CC=golang-codereviews
https://golang.org/cl/146480043
2014-09-29 13:42:33 -07:00
Brad Fitzpatrick
dca460574f net: fix misleading package comment example
Fixes #8607

LGTM=r
R=r
CC=golang-codereviews
https://golang.org/cl/146470043
2014-09-29 12:24:06 -07:00
Brad Fitzpatrick
dfaf1f71e6 net/http: update ProxyFromEnvironment docs for HTTPS_PROXY addition
LGTM=adg
R=adg
CC=golang-codereviews
https://golang.org/cl/142650043
2014-09-24 17:39:00 -07:00
Nigel Tao
e59ad69a44 net/http: allow double-quotes only on cookie values, not cookie
attribute values, a la RFC 6265 section 4.1.1 "Syntax".

Fixes #7751.

LGTM=dr.volker.dobler
R=dr.volker.dobler
CC=bradfitz, golang-codereviews
https://golang.org/cl/148890043
2014-09-25 10:21:52 +10:00
Brad Fitzpatrick
446524269e net/http: check for CloseWrite interface, not TCPConn implementation
Fixes #8724

LGTM=adg
R=adg
CC=golang-codereviews
https://golang.org/cl/148040043
2014-09-24 17:01:54 -07:00
Brad Fitzpatrick
e6f21be3f4 net/http: support https_proxy in ProxyFromEnvironment
Fixes #6181

LGTM=adg
R=adg
CC=golang-codereviews
https://golang.org/cl/148980043
2014-09-24 16:55:39 -07:00
Russ Cox
6077f0fc32 cmd/go: fix bytes and net the right way
Not sure why they used empty.s and all these other
packages were special cased in cmd/go instead.
Add them to the list.

This avoids problems with net .s files being compiled
with gcc in cgo mode and gcc not supporting // comments
on ARM.

Not a problem with bytes, but be consistent.

The last change fixed the ARM build but broke the Windows build.
Maybe *this* will make everyone happy. Sigh.

TBR=iant
CC=golang-codereviews
https://golang.org/cl/144530046
2014-09-24 19:18:01 -04:00
Russ Cox
d2b84dd941 net: only "build" empty.s in non-cgo mode
In cgo mode it gets passed to gcc, and on ARM
it appears that gcc does not support // comments.

TBR=iant
CC=golang-codereviews
https://golang.org/cl/142640043
2014-09-24 19:09:43 -04:00
Russ Cox
a0785a53ad cmd/go: prohibit C sources files unless using cgo
Those C files would have been compiled with 6c.
It's close to impossible to use C correctly anymore,
and the C compilers are going away eventually.
Make them unavailable now.

go1.4.txt change in CL 145890046

LGTM=iant
R=iant
CC=golang-codereviews, r
https://golang.org/cl/149720043
2014-09-24 15:10:38 -04:00
Brad Fitzpatrick
93e5cc224e net/http: replace z_last_test hack with testing.Main
LGTM=adg
R=rsc, adg
CC=golang-codereviews
https://golang.org/cl/144240043
2014-09-22 09:13:09 -04:00
Russ Cox
2c15d45131 net/http: document server recovering panics
Fixes #8594.

LGTM=bradfitz
R=bradfitz
CC=golang-codereviews
https://golang.org/cl/145760043
2014-09-19 13:53:33 -04:00
John Tuley
0c47bd1e61 net/http: ensured that proxy errors are returned by Transport.RoundTrip.
Fixes #8755.

LGTM=bradfitz
R=bradfitz
CC=golang-codereviews, jtuley
https://golang.org/cl/136710044
2014-09-19 11:28:38 -04:00
Russ Cox
76c7548162 net: disable TestDialMultiFDLeak
It fails about 25% of the time on OS X.
I don't know what it's trying to do.
Created issue 8764 to correct this, but for now disable.

LGTM=bradfitz, mikioh.mikioh
R=bradfitz, mikioh.mikioh
CC=golang-codereviews
https://golang.org/cl/144070044
2014-09-18 14:48:26 -04:00
Mikio Hara
484cc67151 net: separate NaCl dependent placeholders from BSD's
To clarify the dependency of NaCl platform.

LGTM=adg
R=golang-codereviews, adg
CC=golang-codereviews
https://golang.org/cl/143830044
2014-09-18 19:17:55 +09:00
Russ Cox
06e4b06893 net/mail: allow us-ascii encoding
Fixes #6611.

LGTM=bradfitz
R=bradfitz
CC=golang-codereviews
https://golang.org/cl/14990045
2014-09-16 17:40:33 -04:00
Russ Cox
95c899f03c net: make TestSelfConnect less fragile
We believe TestSelfConnect can accidentally connect to
something else listening on or dialing from that port.

Fixes #8680.

LGTM=bradfitz
R=bradfitz
CC=golang-codereviews, rlh
https://golang.org/cl/136700043
2014-09-16 14:02:59 -04:00
Brad Fitzpatrick
bb431245cc net/http: don't call FileSystem.Open with unclean index.html path
Fixes #8722

LGTM=adg
R=adg
CC=golang-codereviews
https://golang.org/cl/142090043
2014-09-15 07:14:33 -04:00
Mikio Hara
f956740163 net: fix inconsistent behavior across platforms in SetKeepAlivePeriod
The previous implementation used per-socket TCP keepalive options
wrong. For example, it used another level socket option to control
TCP and it didn't use TCP_KEEPINTVL option when possible.

Fixes #8683.
Fixes #8701.
Update #8679

LGTM=iant
R=golang-codereviews, iant
CC=golang-codereviews
https://golang.org/cl/136480043
2014-09-11 17:56:58 +09:00
Mikio Hara
1fadd9e1ae net: don't set wrong option for controlling tcp keepalive on openbsd
Fixes #8679.

LGTM=iant
R=golang-codereviews, iant
CC=golang-codereviews
https://golang.org/cl/141730043
2014-09-09 07:22:11 +09:00
Russ Cox
c007ce824d build: move package sources from src/pkg to src
Preparation was in CL 134570043.
This CL contains only the effect of 'hg mv src/pkg/* src'.
For more about the move, see golang.org/s/go14nopkg.
2014-09-08 00:08:51 -04:00