| Age | Commit message (Collapse) | Author |
|
Accidental change from fixing Content-Length on 204s
in http://golang.org/issue/6685 earlier.
LGTM=rsc
R=rsc
CC=golang-codereviews
https://golang.org/cl/92400047
|
|
I fixed this data race regression in two ways: in net/http itself, and also
partially reverting the change from https://golang.org/cl/77580046 .
Previously a Read from a strings.Reader or bytes.Reader returning 0 bytes
would not be a memory write. After 77580046 it was. This reverts that back
in case others depended on that. Also adds tests.
Fixes #7856
LGTM=ruiu, iant
R=iant, ruiu
CC=golang-codereviews, gri
https://golang.org/cl/94740044
|
|
I was implementing rules from RFC 2616. The rules are apparently useless,
ambiguous, and too strict for common software on the Internet. (e.g. curl)
Add more tests, including a test of a chunked request.
Fixes #7625
LGTM=dsymonds
R=golang-codereviews, dsymonds
CC=adg, golang-codereviews, rsc
https://golang.org/cl/84480045
|
|
1) Move StateHijacked callback earlier, to make it
panic-proof. A Hijack followed by a panic didn't previously
result in ConnState getting fired for StateHijacked. Move it
earlier, to the time of hijack.
2) Don't fire StateActive unless any bytes were read off the
wire while waiting for a request. This means we don't
transition from New or Idle to Active if the client
disconnects or times out. This was documented before, but not
implemented properly.
This CL is required for an pending fix for Issue 7264
LGTM=josharian
R=josharian
CC=golang-codereviews
https://golang.org/cl/69860049
|
|
The addition of Server.ConnState provides all the necessary
hooks to stop a Server gracefully, but StateNew previously
could fire concurrently with Serve exiting (as it does when
its net.Listener is closed). This previously meant one
couldn't use a WaitGroup incremented in the StateNew hook
along with calling Wait after Serve. Now you can.
Update #4674
LGTM=bradfitz
R=bradfitz
CC=golang-codereviews
https://golang.org/cl/70410044
|
|
Fixes #7291
LGTM=agl
R=golang-codereviews, agl
CC=agl, golang-codereviews
https://golang.org/cl/70250044
|
|
Part of graceful shutdown.
Update #4674
LGTM=adg, josharian
R=adg, josharian, r
CC=golang-codereviews
https://golang.org/cl/69670043
|
|
Update #4674
This allows for all sorts of graceful shutdown policies,
without picking a policy (e.g. lameduck period) and without
adding lots of locking to the server core. That policy and
locking can be implemented outside of net/http now.
LGTM=adg
R=golang-codereviews, josharian, r, adg, dvyukov
CC=golang-codereviews
https://golang.org/cl/69260044
|
|
4 KB is a bit too small in some situations (e.g. panic during a
template execution), and ends up with an unhelpfully-truncated trace.
64 KB should be much more likely to capture the useful information.
There's not a garbage generation issue, since this code should only
be triggered when there's something seriously wrong with the program.
LGTM=bradfitz
R=bradfitz
CC=golang-codereviews
https://golang.org/cl/63520043
|
|
Status codes 204, 304, and 1xx don't allow bodies. We already
had a function for this, but we were hard-coding just 304
(StatusNotModified) in a few places. Use the function
instead, and flesh out tests for all codes.
Fixes #6685
R=golang-codereviews, r
CC=golang-codereviews
https://golang.org/cl/53290044
|
|
Fix another issue (similar to Issue 6995) where there was a
data race when sharing a server handler's Request.Body with
another goroutine that out-lived the Handler's goroutine.
In some cases we were not closing the incoming Request.Body
(which would've required reading it until the end) if we
thought it we thought we were going to be forcibly closing the
underlying net.Conn later anyway. But that optimization
largely moved to the transfer.go *body later, and locking was
added to *body which then detected read-after-close, so now
calling the (*body).Close always is both cheap and correct.
No new test because TestTransportAndServerSharedBodyRace caught it,
albeit only sometimes. Running:
while ./http.test -test.cpu=8 -test.run=TestTransportAndServerSharedBodyRace; do true; done
... would reliably cause a race before, but not now.
Update #6995
Fixes #7092
R=golang-codereviews, khr
CC=golang-codereviews
https://golang.org/cl/51700043
|
|
Our default behavior for the common cases shouldn't lead to
leaked TCP connections (e.g. from people closing laptops) when
their Go servers are exposed to the open Internet without a
proxy in front.
Too many users on golang-nuts have learned this the hard way.
No API change. Only ListenAndServe and ListenAndServeTLS are
updated.
R=golang-codereviews, cespare, gobot, rsc, minux.ma
CC=golang-codereviews
https://golang.org/cl/48300043
|
|
When a connection is hijacked, release the reference to the bufio.Writer
that is used with the chunkWriter. The chunkWriter is not used after
the connection is hijacked.
Also add a test to check that double Hijack calls do something sensible.
benchmark old ns/op new ns/op delta
BenchmarkServerHijack 24137 20629 -14.53%
benchmark old allocs new allocs delta
BenchmarkServerHijack 21 19 -9.52%
benchmark old bytes new bytes delta
BenchmarkServerHijack 11774 9667 -17.90%
R=bradfitz, dave, chris.cahoon
CC=golang-codereviews
https://golang.org/cl/39440044
|
|
Update #4720
R=golang-dev, iant
CC=golang-dev
https://golang.org/cl/44080043
|
|
Fixes #5953
R=dsymonds, bradfitz, rsc
CC=golang-dev
https://golang.org/cl/14434044
|
|
Date header indicated that it contained GMT time,
however it actually sent local time. Fixed by
converting time to UTC.
Also fixes incorrect comment in appendTime().
Regression since CL 9432046.
R=golang-dev, dave, bradfitz
CC=golang-dev
https://golang.org/cl/13386047
|
|
Fixes #4799
R=golang-dev, dave, rsc
CC=golang-dev
https://golang.org/cl/13457047
|
|
R=bradfitz, alberto.garcia.hierro, rsc, adg
CC=golang-dev
https://golang.org/cl/7099045
|
|
Fixes #5377
R=golang-dev, r
CC=golang-dev
https://golang.org/cl/12991046
|
|
Also start of some test helper unification, long overdue.
I refrained from cleaning up the rest in this CL.
Fixes #6157
R=golang-dev, adg
CC=golang-dev
https://golang.org/cl/13030043
|
|
Update #5100
Update #6086
Remove switchReader, switchWriter, switchReaderPair,
switchWriterPair, etc.
Now it only maintains pools of bufio Readers and Writers, but
uses Reset instead of working around all their
previously-associated state.
Compared to before the bufio Reset change, it's the same number of
allocations, and also faster:
benchmark old ns/op new ns/op delta
BenchmarkClientServer 111218 109828 -1.25%
BenchmarkClientServerParallel4 70580 70013 -0.80%
BenchmarkClientServerParallel64 72636 68919 -5.12%
BenchmarkServer 139858 137068 -1.99%
BenchmarkServerFakeConnNoKeepAlive 14619 14314 -2.09%
BenchmarkServerFakeConnWithKeepAlive 12390 11361 -8.31%
BenchmarkServerFakeConnWithKeepAliveLite 7630 7306 -4.25%
BenchmarkServerHandlerTypeLen 9688 9342 -3.57%
BenchmarkServerHandlerNoLen 8700 8470 -2.64%
BenchmarkServerHandlerNoType 9255 8949 -3.31%
BenchmarkServerHandlerNoHeader 7058 6806 -3.57%
benchmark old allocs new allocs delta
BenchmarkClientServer 61 61 0.00%
BenchmarkClientServerParallel4 61 61 0.00%
BenchmarkClientServerParallel64 61 61 0.00%
BenchmarkServer 16 16 0.00%
BenchmarkServerFakeConnNoKeepAlive 24 24 0.00%
BenchmarkServerFakeConnWithKeepAlive 19 19 0.00%
BenchmarkServerFakeConnWithKeepAliveLite 9 9 0.00%
BenchmarkServerHandlerTypeLen 17 17 0.00%
BenchmarkServerHandlerNoLen 14 14 0.00%
BenchmarkServerHandlerNoType 15 15 0.00%
BenchmarkServerHandlerNoHeader 9 9 0.00%
benchmark old bytes new bytes delta
BenchmarkClientServer 6988 6985 -0.04%
BenchmarkClientServerParallel4 6979 6985 0.09%
BenchmarkClientServerParallel64 7002 7019 0.24%
BenchmarkServer 1846 1848 0.11%
BenchmarkServerFakeConnNoKeepAlive 2420 2412 -0.33%
BenchmarkServerFakeConnWithKeepAlive 2126 2129 0.14%
BenchmarkServerFakeConnWithKeepAliveLite 989 990 0.10%
BenchmarkServerHandlerTypeLen 1818 1819 0.06%
BenchmarkServerHandlerNoLen 1775 1777 0.11%
BenchmarkServerHandlerNoType 1783 1785 0.11%
BenchmarkServerHandlerNoHeader 989 990 0.10%
R=golang-dev, r
CC=golang-dev
https://golang.org/cl/12708046
|
|
The ResponseWriter's ReadFrom method was causing side effects on
the output before any data was read.
Now, bail out early and do a normal copy (which does a read
before writing) when our input and output are known to not to
be the pair of types we need for sendfile.
Fixes #5660
R=golang-dev, rsc, nightlyone
CC=golang-dev
https://golang.org/cl/12632043
|
|
HTTP/1.0 connections are closed implicitly, unless otherwise specified.
Note that this change does not test or fix "request too large" responses.
Reasoning: (a) it complicates tests and fixes, (b) they should be rare,
and (c) this is just a minor wire optimization, and thus not really worth worrying
about in this context.
Fixes #5955.
R=golang-dev, bradfitz
CC=golang-dev
https://golang.org/cl/12435043
|
|
A response to a HEAD request is supposed to look the same as a
response to a GET request, just without a body.
HEAD requests are incredibly rare in the wild.
The Go net/http package has so far treated HEAD requests
specially: a Write on our default ResponseWriter returned
ErrBodyNotAllowed, telling handlers that something was wrong.
This was to optimize the fast path for HEAD requests, but:
1) because HEAD requests are incredibly rare, they're not
worth having a fast path for.
2) Letting the http.Handler handle but do nop Writes is still
very fast.
3) this forces ugly error handling into the application.
e.g. https://code.google.com/p/go/source/detail?r=6f596be7a31e
and related.
4) The net/http package nowadays does Content-Type sniffing,
but you don't get that for HEAD.
5) The net/http package nowadays does Content-Length counting
for small (few KB) responses, but not for HEAD.
6) ErrBodyNotAllowed was useless. By the time you received it,
you had probably already done all your heavy computation
and I/O to calculate what to write.
So, this change makes HEAD requests like GET requests.
We now count content-length and sniff content-type for HEAD
requests. If you Write, it doesn't return an error.
If you want a fast-path in your code for HEAD, you have to do
it early and set all the response headers yourself. Just like
before. If you choose not to Write in HEAD requests, be sure
to set Content-Length if you know it. We won't write
"Content-Length: 0" because you might've just chosen to not
write (or you don't know your Content-Length in advance).
Fixes #5454
R=golang-dev, dsymonds
CC=golang-dev
https://golang.org/cl/12583043
|
|
Uglier.
««« original CL description
all: use strings.IndexByte instead of Index where possible
R=golang-dev, khr
CC=golang-dev
https://golang.org/cl/12486043
»»»
R=golang-dev
CC=golang-dev
https://golang.org/cl/12485044
|
|
R=golang-dev, khr
CC=golang-dev
https://golang.org/cl/12486043
|
|
R=golang-dev, bradfitz
CC=golang-dev
https://golang.org/cl/12276043
|
|
Fixes #5953
R=golang-dev, dsymonds
CC=golang-dev
https://golang.org/cl/12117043
|
|
Phrases like "returns whether or not the image is opaque" could be
describing what the function does (it always returns, regardless of
the opacity) or what it returns (a boolean indicating the opacity).
Even when the "or not" is missing, the phrasing is bizarre.
Go with "reports whether", which is still clunky but at least makes
it clear we're talking about the return value.
These were edited by hand. A few were cleaned up in other ways.
R=golang-dev, dsymonds
CC=golang-dev
https://golang.org/cl/11699043
|
|
Several places used io.WriteString unnecessarily when the
static type already implemented WriteString. No need to
check for it at runtime.
R=golang-dev, r
CC=golang-dev
https://golang.org/cl/9608043
|
|
benchmark old ns/op new ns/op delta
BenchmarkServerFakeConnNoKeepAlive 14431 14247 -1.28%
BenchmarkServerFakeConnWithKeepAlive 11618 11357 -2.25%
BenchmarkServerFakeConnWithKeepAliveLite 6735 6427 -4.57%
BenchmarkServerHandlerTypeLen 8842 8740 -1.15%
BenchmarkServerHandlerNoLen 8001 7828 -2.16%
BenchmarkServerHandlerNoType 8270 8227 -0.52%
BenchmarkServerHandlerNoHeader 6148 5920 -3.71%
benchmark old allocs new allocs delta
BenchmarkServerFakeConnNoKeepAlive 30 29 -3.33%
BenchmarkServerFakeConnWithKeepAlive 25 24 -4.00%
BenchmarkServerFakeConnWithKeepAliveLite 10 9 -10.00%
BenchmarkServerHandlerTypeLen 18 17 -5.56%
BenchmarkServerHandlerNoLen 15 14 -6.67%
BenchmarkServerHandlerNoType 16 15 -6.25%
BenchmarkServerHandlerNoHeader 10 9 -10.00%
benchmark old bytes new bytes delta
BenchmarkServerFakeConnNoKeepAlive 2557 2492 -2.54%
BenchmarkServerFakeConnWithKeepAlive 2260 2194 -2.92%
BenchmarkServerFakeConnWithKeepAliveLite 1092 1026 -6.04%
BenchmarkServerHandlerTypeLen 1941 1875 -3.40%
BenchmarkServerHandlerNoLen 1898 1832 -3.48%
BenchmarkServerHandlerNoType 1906 1840 -3.46%
BenchmarkServerHandlerNoHeader 1092 1026 -6.04%
Update #5195
R=golang-dev, daniel.morsing
CC=golang-dev
https://golang.org/cl/9492044
|
|
Don't allocate for the Date or Content-Length headers.
A custom Date header formatter replaces use of time.Format.
benchmark old ns/op new ns/op delta
BenchmarkClientServer 67791 64424 -4.97%
BenchmarkClientServerParallel4 62956 58533 -7.03%
BenchmarkClientServerParallel64 62043 54789 -11.69%
BenchmarkServer 254609 229060 -10.03%
BenchmarkServerFakeConnNoKeepAlive 17038 16316 -4.24%
BenchmarkServerFakeConnWithKeepAlive 14184 13226 -6.75%
BenchmarkServerFakeConnWithKeepAliveLite 8591 7532 -12.33%
BenchmarkServerHandlerTypeLen 10750 9961 -7.34%
BenchmarkServerHandlerNoLen 9535 8935 -6.29%
BenchmarkServerHandlerNoType 9858 9362 -5.03%
BenchmarkServerHandlerNoHeader 7754 6856 -11.58%
benchmark old allocs new allocs delta
BenchmarkClientServer 68 66 -2.94%
BenchmarkClientServerParallel4 68 66 -2.94%
BenchmarkClientServerParallel64 68 66 -2.94%
BenchmarkServer 21 19 -9.52%
BenchmarkServerFakeConnNoKeepAlive 32 30 -6.25%
BenchmarkServerFakeConnWithKeepAlive 27 25 -7.41%
BenchmarkServerFakeConnWithKeepAliveLite 12 10 -16.67%
BenchmarkServerHandlerTypeLen 19 18 -5.26%
BenchmarkServerHandlerNoLen 17 15 -11.76%
BenchmarkServerHandlerNoType 17 16 -5.88%
BenchmarkServerHandlerNoHeader 12 10 -16.67%
Update #5195
R=nigeltao
CC=golang-dev
https://golang.org/cl/9432046
|
|
R=golang-dev, bradfitz
CC=golang-dev
https://golang.org/cl/8896045
|
|
R=golang-dev, r
CC=golang-dev
https://golang.org/cl/8911044
|
|
R=golang-dev, dsymonds, r
CC=golang-dev
https://golang.org/cl/8721045
|
|
We've decided to leave logging to third-parties (there are too
many formats), which others have done.
And we can't change the behavior of the various response
fields at this point anyway. Plus I argue they're correct and
match their documention.
R=golang-dev, r
CC=golang-dev
https://golang.org/cl/8391043
|
|
It was unnecessarily cloning and then mutating a map that had
a very short lifetime (just that function).
No new tests, because they were added in revision 833bf2ef1527
(TestHeaderToWire). The benchmarks below are from the earlier
commit, revision 52e3407d.
I noticed this inefficiency when reviewing a change Peter Buhr
is looking into, which will also use these benchmarks.
benchmark old ns/op new ns/op delta
BenchmarkServerHandlerTypeLen 12547 12325 -1.77%
BenchmarkServerHandlerNoLen 12466 11167 -10.42%
BenchmarkServerHandlerNoType 12699 11800 -7.08%
BenchmarkServerHandlerNoHeader 11901 9210 -22.61%
benchmark old allocs new allocs delta
BenchmarkServerHandlerTypeLen 21 20 -4.76%
BenchmarkServerHandlerNoLen 20 18 -10.00%
BenchmarkServerHandlerNoType 20 18 -10.00%
BenchmarkServerHandlerNoHeader 17 13 -23.53%
benchmark old bytes new bytes delta
BenchmarkServerHandlerTypeLen 1930 1913 -0.88%
BenchmarkServerHandlerNoLen 1912 1879 -1.73%
BenchmarkServerHandlerNoType 1912 1878 -1.78%
BenchmarkServerHandlerNoHeader 1491 1086 -27.16%
R=golang-dev, adg
CC=golang-dev
https://golang.org/cl/8268046
|
|
A chunkWriter and a response are 1:1. Make them contiguous in
memory and save an allocation.
benchmark old ns/op new ns/op delta
BenchmarkServerFakeConnWithKeepAliveLite 10715 10539 -1.64%
benchmark old allocs new allocs delta
BenchmarkServerFakeConnWithKeepAliveLite 21 20 -4.76%
benchmark old bytes new bytes delta
BenchmarkServerFakeConnWithKeepAliveLite 1626 1609 -1.05%
R=golang-dev, gri
CC=golang-dev
https://golang.org/cl/8114043
|
|
benchmark old ns/op new ns/op delta
BenchmarkServerFakeConnWithKeepAliveLite 11031 10689 -3.10%
benchmark old allocs new allocs delta
BenchmarkServerFakeConnWithKeepAliveLite 23 21 -8.70%
benchmark old bytes new bytes delta
BenchmarkServerFakeConnWithKeepAliveLite 1668 1626 -2.52%
R=golang-dev, gri
CC=golang-dev
https://golang.org/cl/8110044
|
|
Add more tests around the various orders handlers can access
and flush response headers.
Also clarify the documentation on fields of response and
chunkWriter.
While there, remove an allocation (a header clone) for simple
handlers.
benchmark old ns/op new ns/op delta
BenchmarkServerFakeConnWithKeepAliveLite 15245 14966 -1.83%
benchmark old allocs new allocs delta
BenchmarkServerFakeConnWithKeepAliveLite 24 23 -4.17%
benchmark old bytes new bytes delta
BenchmarkServerFakeConnWithKeepAliveLite 1717 1668 -2.85%
R=golang-dev, gri
CC=golang-dev
https://golang.org/cl/8101043
|
|
There was another bufio.Writer not being reused, found with
GOGC=off and -test.memprofile.
benchmark old ns/op new ns/op delta
BenchmarkServerFakeConnWithKeepAlive 18270 16046 -12.17%
benchmark old allocs new allocs delta
BenchmarkServerFakeConnWithKeepAlive 38 36 -5.26%
benchmark old bytes new bytes delta
BenchmarkServerFakeConnWithKeepAlive 4598 2488 -45.89%
Update #5100
R=golang-dev, gri
CC=golang-dev
https://golang.org/cl/8038047
|
|
Saves over 8KB of allocations per new connection.
benchmark old ns/op new ns/op delta
BenchmarkServerFakeConnNoKeepAlive 28777 24927 -13.38%
benchmark old allocs new allocs delta
BenchmarkServerFakeConnNoKeepAlive 52 46 -11.54%
benchmark old bytes new bytes delta
BenchmarkServerFakeConnNoKeepAlive 13716 5286 -61.46%
R=golang-dev, adg
CC=golang-dev
https://golang.org/cl/7799047
|
|
R=golang-dev, bradfitz
CC=golang-dev
https://golang.org/cl/7936043
|
|
The example is the same as the FileServer one, but
it's relevant for both.
Also use strings.TrimPrefix while I'm here.
R=golang-dev, rsc
CC=golang-dev
https://golang.org/cl/7598046
|
|
Take advantage of the new terminating statement rule.
R=golang-dev, r, gri
CC=golang-dev
https://golang.org/cl/7712044
|
|
And one real leak in TimeoutHandler.
Fixes #4821
R=golang-dev, adg
CC=golang-dev
https://golang.org/cl/7369056
|
|
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
|
|
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
|
|
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
|
|
R=bradfitz
CC=golang-dev
https://golang.org/cl/7132045
|