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

800 Commits

Author SHA1 Message Date
Brad Fitzpatrick
a2ade45205 net/http: improve test reliability
Fixes #4852

R=golang-dev, adg
CC=golang-dev
https://golang.org/cl/7374045
2013-02-20 16:39:33 -08:00
Akshat Kumar
66b69a1719 net: Plan 9: open data file and set remote-addr properly
The data file should be opened when a Conn is first
established, rather than waiting for the first Read or
Write.

Upon Close, we now make sure to try to close both, the
ctl as well as data files and set both to nil, even in
the face of errors, instead of returning early.

The Accept call was not setting the remote address
of the connection properly. Now, we read the correct
file.

Make functions that establish Conn use newTCPConn
or newUDPConn.

R=rsc, rminnich, ality, dave
CC=golang-dev
https://golang.org/cl/7228068
2013-02-19 17:11:17 -08:00
Mikio Hara
40c2fbf4f2 net: set up IPv6 scoped addressing zone for network facilities
This CL changes nothing to existing API behavior, just sets up
Zone in IPNet and IPAddr structures if possible.

Also does small simplification.

Update #4234.

R=rsc, dave
CC=golang-dev
https://golang.org/cl/7300081
2013-02-20 08:18:04 +09:00
Mikio Hara
e4890e57e1 net: return correct point-to-point interface address on linux
On Linux point-to-point interface an IFA_ADDRESS attribute
represents a peer address. For a correct interface address
we should take an IFA_LOCAL attribute instead.

Fixes #4839.

R=golang-dev, dave, rsc
CC=golang-dev
https://golang.org/cl/7352045
2013-02-20 07:31:44 +09:00
Robin Eklind
d137a2cb56 src: use internal tests if possible
If a test can be placed in the same package ("internal"), it is placed
there. This facilitates testing of package-private details. Because of
dependency cycles some packages cannot be tested by internal tests.

R=golang-dev, rsc, mikioh.mikioh
CC=golang-dev, r
https://golang.org/cl/7323044
2013-02-19 10:02:01 -05:00
Mikio Hara
c02d18ab34 net: add IPConn through Conn test
Also refactors mock ICMP stuff.

R=dave, rsc
CC=golang-dev
https://golang.org/cl/7325043
2013-02-16 12:55:39 +09:00
Adam Langley
5b20a18f3b crypto/x509: support IP SANs.
Subject Alternative Names in X.509 certificates may include IP
addresses. This change adds support for marshaling, unmarshaling and
verifying this form of SAN.

It also causes IP addresses to only be checked against IP SANs,
rather than against hostnames as was previously the case. This
reflects RFC 6125.

Fixes #4658.

R=golang-dev, mikioh.mikioh, bradfitz
CC=golang-dev
https://golang.org/cl/7336046
2013-02-15 10:40:17 -05:00
Alex Brainman
d71b3921f7 net: delete TestDialTimeoutHandleLeak
It is too flaky. Tried to make it more reliable,
but that affects other tests (they run too long),
because we do unusual things here, like attempting
to connect to non-existing address and interrupt.

R=golang-dev, bradfitz, mikioh.mikioh
CC=golang-dev
https://golang.org/cl/7314097
2013-02-15 15:52:12 +11:00
Brad Fitzpatrick
158a0353f7 net: document OpError
Fixes #4797

R=adg, rsc
CC=golang-dev
https://golang.org/cl/7300099
2013-02-14 09:29:34 -08:00
Dave Cheney
2803744b86 net/textproto: more efficient header parsing
A co creation with bradfitz

* add fast path for header lines which are not continuations
* pass hint to better size initial mime header map

lucky(~/go/src/pkg/net/http) % ~/go/misc/benchcmp {golden,new}.txt
benchmark                          old ns/op    new ns/op    delta
BenchmarkReadRequestChrome             10073         8348  -17.12%
BenchmarkReadRequestCurl                4368         4350   -0.41%
BenchmarkReadRequestApachebench         4412         4397   -0.34%
BenchmarkReadRequestSiege               6431         5924   -7.88%
BenchmarkReadRequestWrk                 2820         3146  +11.56%

benchmark                           old MB/s     new MB/s  speedup
BenchmarkReadRequestChrome             60.66        73.18    1.21x
BenchmarkReadRequestCurl               17.85        17.93    1.00x
BenchmarkReadRequestApachebench        18.58        18.65    1.00x
BenchmarkReadRequestSiege              23.48        25.49    1.09x
BenchmarkReadRequestWrk                14.18        12.71    0.90x

benchmark                         old allocs   new allocs    delta
BenchmarkReadRequestChrome                32           26  -18.75%
BenchmarkReadRequestCurl                  15           15    0.00%
BenchmarkReadRequestApachebench           16           15   -6.25%
BenchmarkReadRequestSiege                 22           19  -13.64%
BenchmarkReadRequestWrk                   11           11    0.00%

benchmark                          old bytes    new bytes    delta
BenchmarkReadRequestChrome              3148         2216  -29.61%
BenchmarkReadRequestCurl                 905         1413   56.13%
BenchmarkReadRequestApachebench          956         1413   47.80%
BenchmarkReadRequestSiege               1397         1522    8.95%
BenchmarkReadRequestWrk                  757         1369   80.85%

R=bradfitz
CC=golang-dev
https://golang.org/cl/7300098
2013-02-14 19:35:38 +11:00
Brad Fitzpatrick
cd566958e9 net/http: test that we preserve Go 1.0 Request.Write Host behavior
Fixes #4792

R=golang-dev, rsc
CC=golang-dev
https://golang.org/cl/7314093
2013-02-13 18:33:15 -08:00
Dave Cheney
8c30b3f038 net: remove noisy test for issue 3590
The test for issue 3590 causes an error to be printed to stderr when run (although the error is obscured during go test std). This is confusing for people who get breakage in the net package as the error is harmless and most likely unrelated to their build breakage.

Given the way the test works, by reaching into the guts of the netFD, I can't see a way to silence the error without adding a bunch of code to support the test, therefore I am suggesting the test be removed before Go 1.1 ships.

R=alex.brainman, mikioh.mikioh, rsc
CC=golang-dev
https://golang.org/cl/7307110
2013-02-14 10:11:16 +11:00
Mikio Hara
ee9d148ce1 net: add test for Dial and Listen arguments
R=dave, bradfitz
CC=golang-dev
https://golang.org/cl/7305081
2013-02-14 07:02:32 +09:00
Alex Brainman
ea1f7b8380 net: change server_test.go so we could see failure messages
R=golang-dev, dave
CC=golang-dev
https://golang.org/cl/7323051
2013-02-13 16:17:47 +11:00
Dave Cheney
6ce3e99af0 net/http: more request benchmarks
Add benchmarks for common http benchmarking tools. The intent is to catch optimisations which favor synthetic benchmarks that do not show improvements for real clients like Chrome.

BenchmarkReadRequestChrome        200000             10133 ns/op          60.29 MB/s        3148 B/op         32 allocs/op
BenchmarkReadRequestCurl          500000              4314 ns/op          18.08 MB/s         905 B/op         15 allocs/op
BenchmarkReadRequestApachebench   500000              4363 ns/op          18.79 MB/s         956 B/op         16 allocs/op
BenchmarkReadRequestSiege         500000              6408 ns/op          24.19 MB/s        1397 B/op         22 allocs/op
BenchmarkReadRequestWrk          1000000              2838 ns/op          14.09 MB/s         757 B/op         11 allocs/op

R=golang-dev, bradfitz
CC=golang-dev, haimuiba
https://golang.org/cl/7300075
2013-02-10 08:18:09 +11:00
Mikio Hara
a0430dae04 net: fix unixgram
The socket for AF_UNIX domain with SOCK_DGARM type isn't
allowed to work with syscall listen.

R=rsc
CC=golang-dev
https://golang.org/cl/7310068
2013-02-09 08:18:32 +09:00
Dave Cheney
cccc96b8e9 net/http: add BenchmarkReadRequest
Add benchmark for request parsing. Fixture data is taken from https://github.com/felixge/node-http-perf

% go version
go version devel +28966b7b2f0c Thu Feb 07 20:26:12 2013 -0800 linux/amd64

% go test -run=nil -bench=ReadRequest -benchtime=10s
PASS
BenchmarkReadRequest     2000000   9900 ns/op   61.71 MB/s   3148 B/op   32 allocs/op
ok      net/http        12.180s

R=golang-dev, bradfitz, minux.ma, haimuiba
CC=golang-dev
https://golang.org/cl/7313048
2013-02-09 07:04:07 +11:00
Kamil Kisiel
f26fc0c017 net/http/httptest: add examples
R=golang-dev, adg, bradfitz
CC=golang-dev
https://golang.org/cl/7314046
2013-02-08 09:20:05 -08:00
Mikio Hara
6dfd386005 net: simplify Dial, Listen, ListenPacket and those helpers
R=golang-dev, dave, bradfitz
CC=golang-dev
https://golang.org/cl/7300065
2013-02-08 21:53:10 +09:00
Mikio Hara
dc6e51cfd2 net: delete duplicate listenerSockaddr
R=golang-dev, dave
CC=golang-dev
https://golang.org/cl/7299067
2013-02-08 17:02:08 +09:00
Russ Cox
18441e8ade net: do not use RLock around Accept
It might be non-blocking, but it also might be blocking.
Cannot take the chance, as Accept might block indefinitely
and make it impossible to acquire ForkLock exclusively
(during fork+exec).

Fixes #4737.

R=golang-dev, dave, iant, mikioh.mikioh
CC=golang-dev
https://golang.org/cl/7309050
2013-02-07 22:45:12 -05:00
Ian Lance Taylor
514f10b9ab net: skip TestMulticastListener on Solaris
R=golang-dev, minux.ma
CC=golang-dev
https://golang.org/cl/7308060
2013-02-07 09:58:42 -08:00
Ian Lance Taylor
0592c44956 net: permit pollster DelFD to return whether to call Wakeup
This is necessary for systems that use select as the pollster,
such as Solaris (supported by gccgo).  It corresponds to the
bool returned by AddFD.  In general it's not clearly defined
what happens when a descriptor used in a select is closed, and
different systems behave differently.  Waking up the select
will cause the right thing to happen: the closed descriptor
will be dropped from the next iteration.

R=golang-dev, bradfitz
CC=golang-dev
https://golang.org/cl/7303056
2013-02-06 17:18:53 -08:00
Albert Strasheim
309d88e28c syscall, net: Fix unix socket autobind on Linux.
R=rsc, iant, mikioh.mikioh
CC=golang-dev
https://golang.org/cl/7300047
2013-02-06 06:45:57 -08:00
Brad Fitzpatrick
d1e16d06b4 net/http: fix Server blocking after a Handler's Write fails
If a Handle's Write to a ResponseWriter fails (e.g. via a
net.Conn WriteDeadline via WriteTimeout on the Server), the
Server was blocking forever waiting for reads on that
net.Conn, even after a Write failed.

Instead, once we see a Write fail, close the connection,
since it's then dead to us anyway.

Fixes #4741

R=golang-dev, adg
CC=golang-dev
https://golang.org/cl/7301043
2013-02-04 20:26:25 -08:00
Brad Fitzpatrick
92e4645f31 net/http: add Next Protocol Negotation upgrade support to the Server
This provides the mechanism to connect SPDY support to the http
package, without pulling SPDY into the standard library.

R=rsc, agl, mikioh.mikioh
CC=golang-dev
https://golang.org/cl/7287045
2013-02-04 13:55:38 -08:00
Brad Fitzpatrick
022504b3ab net/http: fix when server deadlines get extended
Deadlines should be extended at the beginning of
a request, not at the beginning of a connection.

Fixes #4676

R=golang-dev, fullung, patrick.allen.higgins, adg
CC=golang-dev
https://golang.org/cl/7220076
2013-02-04 13:52:45 -08:00
Alex Brainman
94064548c6 net: use windows sysSocket everywhere
R=golang-dev, bradfitz, dave
CC=golang-dev
https://golang.org/cl/7273046
2013-02-04 16:03:41 +11:00
Alex Brainman
bc9999337b net: prevent races during windows lookup calls
This only affects code (with exception of lookupProtocol)
that is only executed on older versions of Windows.

R=rsc, bradfitz
CC=golang-dev
https://golang.org/cl/7293043
2013-02-04 13:05:20 +11:00
Kyle Lemons
9bfd3c3937 testing: add AllocsPerRun
This CL also replaces similar loops in other stdlib
package tests with calls to AllocsPerRun.

Fixes #4461.

R=minux.ma, rsc
CC=golang-dev
https://golang.org/cl/7002055
2013-02-02 22:52:29 -05:00
Alex Brainman
6d175e243a net: use windows GetAddrInfoW in LookupPort when possible
R=golang-dev, bradfitz
CC=golang-dev
https://golang.org/cl/7252045
2013-01-18 17:05:04 +11:00
Brad Fitzpatrick
e515d80d5d bytes, strings: add TrimPrefix and TrimSuffix
Everybody either gets confused and thinks this is
TrimLeft/TrimRight or does this by hand which gets
repetitive looking.

R=rsc, kevlar
CC=golang-dev
https://golang.org/cl/7239044
2013-02-01 08:41:25 -08:00
Russ Cox
4085426f7d net/url: normalize scheme to lower case (http not HTTP)
Also document %2f vs / ambiguity in URL.Path.

Fixes #3913.
Fixes #3659.

R=golang-dev, bradfitz
CC=golang-dev
https://golang.org/cl/7225076
2013-01-31 13:45:43 -08:00
Brad Fitzpatrick
1aa56a2396 net/http: fix race
Fixes #4724

R=golang-dev, rsc
CC=golang-dev
https://golang.org/cl/7225071
2013-01-30 15:10:07 -08:00
Jeff R. Allen
6563d8623d syscall: handle empty address in ReadFrom better
Handle return values from recvfrom correctly when the
kernel decides to not return an address.

Fixes #4636.
Fixes #4352.

R=rsc, mikioh.mikioh, dave
CC=golang-dev
https://golang.org/cl/7058062
2013-01-30 10:02:01 -08:00
Michael Teichgräber
ad341843a7 net: SplitHostPort: adjust error message for missing port in IPv6 addresses
An hostport of "[::1]" now results in the same error message
"missing port in address" as the hostport value "127.0.0.1",
so SplitHostPort won't complain about "too many colons
in address" anymore for an IPv6 address missing a port.

Added tests checking the error values.

Fixes #4526.

R=dave, rsc, mikioh.mikioh
CC=golang-dev
https://golang.org/cl/7038045
2013-01-30 09:25:16 -08:00
Ian Lance Taylor
2cd5b01454 net: fix windows build
R=golang-dev, minux.ma
CC=golang-dev
https://golang.org/cl/7229050
2013-01-28 09:37:10 -08:00
Ian Lance Taylor
31f58dce67 net, syscall: use accept4 and SOCK_CLOEXEC on Linux
R=golang-dev, bradfitz, mikioh.mikioh, dave, minux.ma
CC=golang-dev
https://golang.org/cl/7227043
2013-01-28 08:54:15 -08:00
Rémy Oudompheng
75104237c8 all: make tests able to run multiple times.
It is now possible to run "go test -cpu=1,2,4 std"
successfully.

Fixes #3185.

R=golang-dev, dave, minux.ma, bradfitz
CC=golang-dev
https://golang.org/cl/7196052
2013-01-27 00:24:09 +01:00
John Graham-Cumming
3c77b8961c net/http: fix Content-Length/Transfer-Encoding on HEAD requests
net/http currently assumes that the response to a HEAD request
    will always have a Content-Length header. This is incorrect.

RFC2616 says: "The HEAD method is identical to GET except that
the server MUST NOT return a message-body in the response. The
metainformation contained in the HTTP headers in response to a
HEAD request SHOULD be identical to the information sent in
response to a GET request. This method can be used for
obtaining metainformation about the entity implied by the
request without transferring the entity-body itself. This
method is often used for testing hypertext links for validity,
accessibility, and recent modification."

This means that three cases are possible: a Content-Length
header, a Transfer-Encoding header or neither. In the wild the
following sites exhibit these behaviours (curl -I):

HEAD on http://www.google.co.uk/ has Transfer-Encoding: chunked
HEAD on http://www.bbc.co.uk/    has Content-Length: 45247
HEAD on http://edition.cnn.com/  has neither header

This patch does not remove the ErrMissingContentLength error
for compatibility reasons, but it is no longer used.

R=golang-dev, bradfitz
CC=golang-dev
https://golang.org/cl/7182045
2013-01-25 10:20:19 -08:00
Dave Cheney
6a9e956f19 all: use t.Skip{,f}
Replace various t.Log{,f} ; return checks with t.Skip{,f}.

R=golang-dev, n13m3y3r, bradfitz, adg, mikioh.mikioh
CC=golang-dev
https://golang.org/cl/7193044
2013-01-24 17:32:10 +11:00
Andrew Gerrand
da82dfaccd net/url: use bytes.Buffer in (*URL).String
BenchmarkString before:

        11990 ns/op            1621 B/op         73 allocs/op

Using bytes.Buffer:

        8774 ns/op            1994 B/op         40 allocs/op

I also tried making a version of escape() that writes directly to the
bytes.Buffer, but it only saved 1 alloc/op and increased CPU time by
about 10%. Didn't seem worth the extra code path.

R=bradfitz
CC=golang-dev
https://golang.org/cl/7182050
2013-01-23 12:17:11 +11:00
Andrew Gerrand
cdd6ae1288 net/url: generate correct Path when hostname empty
Parse("file:///foo") previously returned a URL with Scheme "file"
and Path "///foo". Now it returns a URL with Path "/foo",
such that
        &URL{Scheme: "file", Path: "/foo"}.String() == "file:///foo"

This means that parsing and stringifying the URL "file:/foo"
returns "file:///foo", technically a regression but one that only
affects a corner case.

Fixes #4189.

R=bradfitz, rsc
CC=golang-dev
https://golang.org/cl/7135051
2013-01-23 11:37:06 +11:00
Mikio Hara
12e7397ebb net: don't return nil interface address on netbsd
On NetBSD routing sockaddrs for interface address contain sockaddr_dl.

R=dave, rsc
CC=golang-dev
https://golang.org/cl/7085064
2013-01-23 07:11:22 +09:00
Mikio Hara
3454b6bf82 undo CL 5687057 / 58bc8aae4abb
Fortunately we have never seen the panic on sockaddrToTCP
in the past year.

««« original CL description
net: panic if sockaddrToTCP returns nil incorrectly
Part of diagnosing the selfConnect bug
TBR=dsymonds

R=golang-dev
CC=golang-dev
https://golang.org/cl/5687057
»»»

R=golang-dev, minux.ma
CC=golang-dev
https://golang.org/cl/7137063
2013-01-19 23:13:01 +09:00
Matthew Dempsky
1a03580ef1 net/http: Serve creates service goroutines, not service threads
R=bradfitz
CC=golang-dev
https://golang.org/cl/7132045
2013-01-16 14:05:41 -08:00
Brad Fitzpatrick
3b73aaafdc net/http: fix racy test
We need to wait for the handler to actually finish running,
not almost be done running.

This was always a bug, but now that handler output is buffered
it shows up easily on GOMAXPROCS >1 systems.

R=golang-dev, iant
CC=golang-dev
https://golang.org/cl/7109043
2013-01-15 09:13:05 -08:00
Mikio Hara
6d725e97e3 net: simplify ListenMulticastUDP
R=rsc, iant, dave
CC=golang-dev
https://golang.org/cl/6999053
2013-01-15 08:53:12 +09:00
Brad Fitzpatrick
05bf9a456a net/http/cgi: fix test case sensitivity on Windows
Fixes #4645

R=golang-dev, alex.brainman, minux.ma
CC=golang-dev
https://golang.org/cl/7105047
2013-01-11 15:11:08 -08:00
Brad Fitzpatrick
bef4cb475c net/http: buffer before chunking
This introduces a buffer between writing from a handler and
writing chunks.  Further, it delays writing the header until
the first full chunk is ready.  In the case where the first
full chunk is also the final chunk (for small responses), that
means we can also compute a Content-Length, which is a nice
side effect for certain benchmarks.

Fixes #2357

R=golang-dev, dave, minux.ma, rsc, adg, balasanjay
CC=golang-dev
https://golang.org/cl/6964043
2013-01-11 10:03:43 -08:00