Compare commits

...

6 Commits

Author SHA1 Message Date
Andrew Gerrand f8f91591b7 [release-branch.go1.2] go.tools/playground/socket: require origin to set up socket handler
««« CL 95030044 / bda3619e7a2c
go.tools/playground/socket: require origin to set up socket handler

This prevents cross-site request forgery attacks.

LGTM=rsc
R=rsc
CC=golang-codereviews
https://golang.org/cl/95030044
»»»

TBR=rsc
CC=golang-dev
https://golang.org/cl/97040044
2014-05-05 08:51:42 -07:00
Andrew Gerrand 5849dad824 [release-branch.go1.2] godoc/static: update site policies link
««« CL 74900047 / 1c14028dc979
godoc/static: update site policies link

Fixes golang/go#7520.

LGTM=bradfitz
R=golang-codereviews, bradfitz
CC=golang-codereviews
https://golang.org/cl/74900047
»»»

LGTM=iant
R=golang-codereviews, iant
CC=golang-dev
https://golang.org/cl/83350043
2014-04-02 09:15:59 +11:00
Andrew Gerrand 161de53d86 [release-branch.go1.2] go.tools/blog: strip prefix when serving static content
««« CL 22700043 / 8cdf69ad05e9
go.tools/blog: strip prefix when serving static content

This fix permits godoc to serve images correctly under /blog/.

R=golang-dev, dsymonds
CC=golang-dev
https://golang.org/cl/22700043
»»»

R=golang-dev, dsymonds
CC=golang-dev
https://golang.org/cl/23400043
2013-11-08 13:58:44 +11:00
Andrew Gerrand 72b8aac9ec [release-branch.go1.2] blog: Fix atom feed's `updated' time when there's only one article.
««« CL 18420044 / e145aeb0df07
blog: Fix atom feed's `updated' time when there's only one article.

When computing the time for the "updated" tag of the atom feed, the
current code checks if there is more than one article and if that is
not true, it sets the time to the zero time.Time. This means that
the feed also gets the zero time in this tag when there is exactly one
article.

This trivial patch fixes this so that when there is exactly one
article, the time is set to that article's time.

R=golang-dev, adg
CC=golang-dev
https://golang.org/cl/18420044

»»»

R=golang-dev, dsymonds
CC=golang-dev
https://golang.org/cl/23390043
2013-11-08 13:47:24 +11:00
Andrew Gerrand 4b93659ce3 [release-branch.go1.2] blog: Make the atom feed title configurable.
««« CL 16830043 / 963dd9f808db
blog: Make the atom feed title configurable.

The blog code is quite generic and with the replacement of template and
static files, it can be re-used. But the atom feed title is hard-coded
into the code. This patch adds a field to set the atom feed title to
the Config structure and uses it in the code where the title was
previously hard-coded.

A CL sent separately will set this Config field in the main package in
the go.blog sub-repository. (See CL 16850043 for that other patch).

R=golang-dev, adg
CC=golang-dev
https://golang.org/cl/16830043

»»»

R=golang-dev, dsymonds
CC=golang-dev
https://golang.org/cl/23380044
2013-11-08 13:45:56 +11:00
Andrew Gerrand 432822781f [release-branch.go1.2] create branch 2013-10-23 10:31:26 +04:00
5 changed files with 35 additions and 10 deletions

1
README
View File

@ -8,3 +8,4 @@ Packages include a type-checker for Go and an implementation of the Single Stati
Assignment (SSA) representation for Go programs.
To submit changes to this repository, see http://golang.org/doc/contribute.html.

View File

@ -36,8 +36,9 @@ type Config struct {
GodocURL string // The base URL of godoc (for menu bar; no trailing slash).
Hostname string // Server host name, used for rendering ATOM feeds.
HomeArticles int // Articles to display on the home page.
FeedArticles int // Articles to include in Atom and JSON feeds.
HomeArticles int // Articles to display on the home page.
FeedArticles int // Articles to include in Atom and JSON feeds.
FeedTitle string // The title of the Atom XML feed
PlayEnabled bool
}
@ -117,7 +118,7 @@ func NewServer(cfg Config) (*Server, error) {
}
// Set up content file server.
s.content = http.FileServer(http.Dir(cfg.ContentPath))
s.content = http.StripPrefix(s.cfg.BasePath, http.FileServer(http.Dir(cfg.ContentPath)))
return s, nil
}
@ -258,11 +259,11 @@ func (s *Server) loadDocs(root string) error {
// atomFeed field.
func (s *Server) renderAtomFeed() error {
var updated time.Time
if len(s.docs) > 1 {
if len(s.docs) > 0 {
updated = s.docs[0].Time
}
feed := atom.Feed{
Title: "The Go Programming Language Blog",
Title: s.cfg.FeedTitle,
ID: "tag:" + s.cfg.Hostname + ",2013:" + s.cfg.Hostname,
Updated: atom.Time(updated),
Link: []atom.Link{{

View File

@ -72,7 +72,7 @@ func main() {
<div id="footer">
Build version {{html .Version}}.<br>
Except as <a href="http://code.google.com/policies.html#restrictions">noted</a>,
Except as <a href="https://developers.google.com/site-policies#restrictions">noted</a>,
the content of this page is licensed under the
Creative Commons Attribution 3.0 License,
and code is licensed under a <a href="/LICENSE">BSD license</a>.<br>

View File

@ -222,7 +222,7 @@ func main() {
<div id="footer">
Build version {{html .Version}}.<br>
Except as <a href="http://code.google.com/policies.html#restrictions">noted</a>,
Except as <a href="https://developers.google.com/site-policies#restrictions">noted</a>,
the content of this page is licensed under the
Creative Commons Attribution 3.0 License,
and code is licensed under a <a href="/LICENSE">BSD license</a>.<br>

View File

@ -22,6 +22,8 @@ import (
"io"
"io/ioutil"
"log"
"net/http"
"net/url"
"os"
"os/exec"
"path/filepath"
@ -35,9 +37,6 @@ import (
"code.google.com/p/go.net/websocket"
)
// Handler implements a WebSocket handler for a client connection.
var Handler = websocket.Handler(socketHandler)
// Environ provides an environment when a binary, such as the go tool, is
// invoked.
var Environ func() []string = os.Environ
@ -65,6 +64,30 @@ type Options struct {
Race bool // use -race flag when building code (for "run" only)
}
// NewHandler returns a websocket server which checks the origin of requests.
func NewHandler(origin *url.URL) websocket.Server {
return websocket.Server{
Config: websocket.Config{Origin: origin},
Handshake: handshake,
Handler: websocket.Handler(socketHandler),
}
}
// handshake checks the origin of a request during the websocket handshake.
func handshake(c *websocket.Config, req *http.Request) error {
o, err := websocket.Origin(c, req)
if err != nil {
log.Println("bad websocket origin:", err)
return websocket.ErrBadWebSocketOrigin
}
ok := c.Origin.Scheme == o.Scheme && c.Origin.Host == o.Host
if !ok {
log.Println("bad websocket origin:", o)
return websocket.ErrBadWebSocketOrigin
}
return nil
}
// socketHandler handles the websocket connection for a given present session.
// It handles transcoding Messages to and from JSON format, and starting
// and killing processes.