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

388 Commits

Author SHA1 Message Date
Brad Fitzpatrick
bba7396fbd strings: implement a faster byte->string Replacer
This implements a replacer for when all old strings are single
bytes, but new values are not.

BenchmarkHTMLEscapeNew   1000000   1090 ns/op
BenchmarkHTMLEscapeOld   1000000   2049 ns/op

R=rsc
CC=golang-dev
https://golang.org/cl/5176043
2011-10-03 15:19:04 -07:00
Brad Fitzpatrick
f75ff01f44 strings: implement a faster byte->byte Replacer
When all old & new string values are single bytes,
byteReplacer is now used, instead of the generic
algorithm.

BenchmarkGenericMatch       10000  102519 ns/op
BenchmarkByteByteMatch    1000000    2178 ns/op

fast path, when nothing matches:
BenchmarkByteByteNoMatch  1000000    1109 ns/op

comparisons to multiple Replace calls:
BenchmarkByteByteReplaces  100000   16164 ns/op

comparison to strings.Map:
BenchmarkByteByteMap       500000    5454 ns/op

R=rsc
CC=golang-dev
https://golang.org/cl/5175050
2011-10-03 13:12:01 -07:00
David Symonds
39493be294 io: rename Copyn to CopyN.
R=golang-dev, r
CC=golang-dev
https://golang.org/cl/5157045
2011-09-30 13:13:39 -07:00
Brad Fitzpatrick
58a5f1e84f http: don't send a 400 Bad Request after a client shutdown
Fixes #2312

R=golang-dev, dsymonds
CC=golang-dev
https://golang.org/cl/5143049
2011-09-28 09:27:11 -07:00
Brad Fitzpatrick
cf6d0175d9 http: add Location method to Response
Fixes #2300

R=golang-dev, rsc
CC=golang-dev
https://golang.org/cl/5117041
2011-09-23 10:57:31 -07:00
Brad Fitzpatrick
96f968df9c http: add a (disabled) test for TLS handshake timeouts
It's currently broken and disabled, pending a fix
for Issue 2281.

R=golang-dev, adg
CC=golang-dev
https://golang.org/cl/5092045
2011-09-21 08:30:47 -07:00
Brad Fitzpatrick
76e705310a httptest: add NewUnstartedServer
This allows testing TLS with different http.Server
options (timeouts, limits).

R=golang-dev, rsc
CC=golang-dev
https://golang.org/cl/5094043
2011-09-20 13:02:10 -07:00
Brad Fitzpatrick
3c3a86ccc7 http: fix TLS handshake blocking server accept loop
Fixes #2263

R=golang-dev, adg
CC=golang-dev
https://golang.org/cl/5076042
2011-09-19 19:56:51 -07:00
Dave Grijalva
80700eb817 http: always include Content-Length header, even for 0
fixes #2221

R=golang-dev, bradfitz
CC=golang-dev
https://golang.org/cl/4952052
2011-09-19 11:41:09 -07:00
Brad Fitzpatrick
6b6cb725e9 http: prevent DumpRequest from adding implicit headers
Fixes #2272

R=rsc
CC=golang-dev
https://golang.org/cl/5043051
2011-09-19 10:22:53 -07:00
Brad Fitzpatrick
48ff4a849c http: check explicit wrong Request.ContentLength values
R=golang-dev, rsc
CC=golang-dev
https://golang.org/cl/5070041
2011-09-19 09:01:32 -07:00
Yasuhiro Matsumoto
048ec75801 http/cgi: clean up environment.
clean up duplicate environment for CGI.
overriding former by latter.
On windows, When there are duplicated environments like following,

SCRIPT_FILENAME=c:/progra~1/php/php-cgi.exe
SCRIPT_FILENAME=/foo.php

CreateProcess use first entry.

If make cgi.Handle like following,

        cgih = cgi.Handler{
                Path: "c:/strawberry/perl/bin/perl.exe",
                Dir:  "c:/path/to/webroot",
                Root: "c:/path/to/webroot",
                Args: []string{"foo.php"},
                Env:  []string{"SCRIPT_FILENAME=foo.php"},
        }

http/cgi should behave "SCRIPT_FILENAME is foo.php".
But currently, http/cgi is set duplicate environment entries.
So, browser show binary dump of "php-cgi.exe" that is specified indented
SCRIPT_FILENAME in first entry.
This change clean up duplicates, and use latters.

R=golang-dev, bradfitz, bradfitz
CC=golang-dev
https://golang.org/cl/5010044
2011-09-16 10:36:54 -07:00
Brad Fitzpatrick
e30b9fd87e http: MaxBytesReader doc cleanups
Comments from rsc after 4921049 was submitted.

R=rsc
CC=golang-dev
https://golang.org/cl/5034042
2011-09-15 14:26:22 -07:00
Brad Fitzpatrick
758b62bf6a http: document that Response.Body is non-nil
Fixes #2208

R=golang-dev, rsc
CC=golang-dev
https://golang.org/cl/5011051
2011-09-15 14:09:53 -07:00
Brad Fitzpatrick
b955e26564 http/cgi: add openbsd environment configuration
R=iant, iant
CC=golang-dev
https://golang.org/cl/5016051
2011-09-15 12:41:00 -07:00
Brad Fitzpatrick
7233dcde99 http: fix WriteProxy documentation
Fixes #2258

R=golang-dev, rsc
CC=golang-dev
https://golang.org/cl/5016048
2011-09-15 10:28:55 -07:00
Ian Lance Taylor
9377b28833 http: Alphabetize imports.
R=golang-dev, bradfitz
CC=golang-dev
https://golang.org/cl/5002043
2011-09-13 09:38:26 -07:00
Rob Pike
7d43b84282 time: make Weekday a method.
Weekday is redundant information for a Time structure.
When parsing a time with a weekday specified, it can create an
incorrect Time value.
When parsing a time without a weekday specified, people
expect the weekday to be set.
Fix all three problems by computing the weekday on demand.

This is hard to gofix, since we must change the type of the node.
Since uses are rare and existing code will be caught by the compiler,
there is no gofix module here.

Fixes #2245.

R=golang-dev, bradfitz, rsc
CC=golang-dev
https://golang.org/cl/4974077
2011-09-12 11:47:55 -07:00
Robert Griesemer
61650b21d6 cleanup: gofmt -s -w src misc
R=r
CC=golang-dev
https://golang.org/cl/4984052
2011-09-06 16:04:55 -07:00
Russ Cox
686181edfe url: handle ; in ParseQuery
Most web frameworks allow ; as a synonym for &,
following a recommendation in some versions of
the HTML specification.  Do the same.

Remove overuse of Split.

Move ParseQuery tests from package http to package url.

Fixes #2210.

R=golang-dev, r
CC=golang-dev
https://golang.org/cl/4973062
2011-09-06 12:24:24 -04:00
Brad Fitzpatrick
7349d21f8e http: add file protocol transport
Off by default (security risk), but users can
wire it up if desired.

Fixes #2113

R=rsc, bradfitz
CC=golang-dev
https://golang.org/cl/4959049
2011-08-30 21:47:41 -07:00
Brad Fitzpatrick
822804c600 http: support setting Transport's TLS client config
R=golang-dev, adg
CC=golang-dev
https://golang.org/cl/4964043
2011-08-26 10:06:35 +04:00
Dave Cheney
8511ed454a http: return 413 instead of 400 when the request body is too large
RFC2616 says servers should return this status code when
rejecting requests that are too large.

http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.4.14

R=bradfitz
CC=golang-dev
https://golang.org/cl/4962041
2011-08-25 14:00:00 +04:00
Brad Fitzpatrick
fa6d038e98 http: adjust test threshold for larger suse buffers
My theory is that suse has larger TCP buffer sizes
by default.  I now check over 100MB, rather than over 2MB.
100MB is ~halfway between the 1MB limit and the 200MB
request that's attempted.

R=golang-dev, dsymonds
CC=golang-dev
https://golang.org/cl/4926048
2011-08-24 16:09:49 +04:00
Brad Fitzpatrick
bb4cf3f351 http: on invalid request, send 400 response
Fixes #2160

R=golang-dev, dsymonds
CC=golang-dev
https://golang.org/cl/4930049
2011-08-24 13:10:22 +04:00
Russ Cox
03582b3308 http: delete error kludge
The kludge is targeted at broken web browsers
like Chrome and IE, but it gets in the way of
sending 400 or 500-series error results with
formatted bodies in response to AJAX requests
made by pages executing in those browsers.

Now the AJAX cases will work and Chrome
and IE will be as broken with Go servers as
they are with all the other servers.

Fixes #2169.

R=bradfitz, dsymonds
CC=golang-dev
https://golang.org/cl/4930047
2011-08-23 22:39:25 -04:00
Brad Fitzpatrick
f0ef4f4746 http: add MaxBytesReader to limit request body size
This adds http.MaxBytesReader, similar to io.LimitReader,
but specific to http, and for preventing a class of DoS
attacks.

This also makes the 10MB ParseForm limit optional (if
not already set by a MaxBytesReader), documents it,
and also adds "PUT" as a valid verb for parsing forms
in the request body.

Improves issue 2093 (DoS protection)
Fixes #2165 (PUT form parsing)

R=golang-dev, adg
CC=golang-dev
https://golang.org/cl/4921049
2011-08-23 12:17:21 +04:00
Brad Fitzpatrick
a986d98053 mime: ParseMediaType returns os.Error now, not a nil map
ParseMediaType previously documented that it always returned
a non-nil map, but also documented that it returned a nil map
to signal an error.

That is confusing, contradictory and not Go-like.

Now it returns (mediatype string, params map, os.Error).

R=golang-dev, r
CC=golang-dev
https://golang.org/cl/4867054
2011-08-18 12:51:23 -07:00
Rob Pike
8380ff34ed http: remove a TODO due to new behavior of nil maps
R=golang-dev, dsymonds, adg
CC=golang-dev
https://golang.org/cl/4907049
2011-08-18 11:01:43 +10:00
Rob Pike
1d8f822c17 url: new package
This is just moving the URL code from package http into its own package,
which has been planned for a while.
Besides clarity, this also breaks a nascent dependency cycle the new template
package was about to introduce.

Add a gofix module, url, and use it to generate changes outside http and url.

Sadness about the churn, gladness about some of the naming improvements.

R=dsymonds, bradfitz, rsc, gustavo, r
CC=golang-dev
https://golang.org/cl/4893043
2011-08-17 13:36:02 +10:00
Dave Grijalva
8f3c7497ac http: corrects undocumented side effects in http.DefaultTransport's RoundTrip method
Fixes #2140.

The http.DefaultTransport's RoundTrip method leaves the http.Request object
in an altered state after performing the round trip.  This patch removes
the header from the Request before returning to the client.

R=golang-dev, bradfitz
CC=golang-dev
https://golang.org/cl/4857041
2011-08-10 14:16:13 -07:00
Brad Fitzpatrick
31fa584906 http: fix ParseMultipartForm after MultipartReader error
Addresses part of issue 2093
Thanks to espians....@

R=golang-dev, nigeltao
CC=golang-dev
https://golang.org/cl/4808087
2011-08-10 08:08:53 -07:00
Brad Fitzpatrick
d24a9785eb http: configurable and default request header size limit
This addresses the biggest DoS in issue 2093

R=golang-dev, dsymonds
CC=golang-dev
https://golang.org/cl/4841050
2011-08-09 10:55:14 -07:00
Yasuhiro Matsumoto
29df7bb7ec http: add test to serve content in index.html
R=golang-dev, bradfitz
CC=golang-dev
https://golang.org/cl/4798071
2011-08-09 10:25:53 -07:00
Yasuhiro Matsumoto
62d4b8ebd2 http: correct path to serve index.html.
calling filepath.FromSlash(x) make invalid character to serve file.
Fixes #2128

R=golang-dev, alex.brainman, rsc
CC=golang-dev
https://golang.org/cl/4810064
2011-08-04 08:20:53 -04:00
David Symonds
4143491c4a http: add more MPEG-4 MIME types to sniffer, and disable MP4 sniffing.
R=rsc
CC=golang-dev
https://golang.org/cl/4808056
2011-08-04 22:10:17 +10:00
Alex Brainman
8800f7cb55 http: correct format flags when printing errors during tests
R=golang-dev, dsymonds
CC=golang-dev
https://golang.org/cl/4809065
2011-08-01 11:50:50 +10:00
Andrew Balholm
3de6228aea http: make serveFile redirects relative to work with StripPrefix
serveFile was using absolute redirects, which didn't work under StripPrefix.
Now it uses relative redirects.

R=golang-dev, rsc, bradfitz
CC=golang-dev, kevlar
https://golang.org/cl/4789042
2011-07-28 11:43:16 -07:00
John Asmuth
2f4632febc container/vector: removed some uses of container/vector in other pkgs
R=gri
CC=golang-dev
https://golang.org/cl/4823054
2011-07-27 15:23:42 -07:00
Robert Griesemer
e21f69338b http: set content type for fileserver directory listings
R=bradfitz, rsc
CC=golang-dev
https://golang.org/cl/4815062
2011-07-26 11:30:11 -07:00
David Symonds
e527d49e55 http: implement MP4 sniffing.
R=rsc
CC=golang-dev
https://golang.org/cl/4809044
2011-07-26 13:28:20 +10:00
Rob Pike
54045e6bcd pkg/http: fix a couple of error messages
R=golang-dev, dsymonds
CC=golang-dev
https://golang.org/cl/4805048
2011-07-22 17:11:44 +10:00
David Symonds
99e5d48e59 http: clarify use of w.conn.body in Write when sniffing.
R=gri, r, r, rsc
CC=golang-dev
https://golang.org/cl/4794047
2011-07-22 13:52:21 +10:00
Russ Cox
301d8a6d4a http: fix chunking bug during content sniffing
R=golang-dev, bradfitz, gri
CC=golang-dev
https://golang.org/cl/4807044
2011-07-21 14:29:14 -04:00
Russ Cox
17d9093bf2 undo CL 4808044 / 1bd754e69ce7
ServeMux depends on having a URL
in order to mux.  It might be that the right
fix is to have CONNECT handlers just not
look at URL.

««« original CL description
http: do not parse req.URL for CONNECT

CONNECT's argument is not a URL.

R=golang-dev, bradfitz, rsc
CC=golang-dev
https://golang.org/cl/4808044

»»»

TBR=bradfitz
CC=golang-dev
https://golang.org/cl/4798046
2011-07-21 13:25:55 -04:00
Yasuhiro Matsumoto
bf5ec12dd5 http: do not parse req.URL for CONNECT
CONNECT's argument is not a URL.

R=golang-dev, bradfitz, rsc
CC=golang-dev
https://golang.org/cl/4808044
2011-07-21 11:33:59 -04:00
David Symonds
6c46afdf41 http: disable sniffer for now.
Something is broken, and investigation is underway.
In the meantime, godoc is broken, so disable sniffing for now
by reverting to the pre-sniffer state.

R=r
CC=golang-dev
https://golang.org/cl/4809046
2011-07-21 22:20:09 +10:00
David Symonds
78c89d21bc http: sniffing algorithm.
This follows draft-ietf-websec-mime-sniff-03 in its intent,
though not its algorithmic specification.

R=rsc
CC=golang-dev
https://golang.org/cl/4746042
2011-07-21 08:38:35 +10:00
Brad Fitzpatrick
3745716bc3 http: let FileServer work when path doesn't begin with a slash
... as when it's over-stripped with StripPrefix.

R=golang-dev, andybalholm, rsc
CC=golang-dev
https://golang.org/cl/4759052
2011-07-18 09:04:48 -07:00
David Symonds
a8e0035bd3 http: drain the pipe output in TestHandlerPanic to avoid logging deadlock.
R=r
CC=golang-dev
https://golang.org/cl/4756047
2011-07-18 12:59:16 +10:00