gofixes for latest Go changes

Change-Id: Ib7b3aea5adff0e1683bcb421cc3549c31d9fe174
This commit is contained in:
Brad Fitzpatrick 2011-08-25 19:14:47 +04:00
parent 7f2f506132
commit 88c89757e1
17 changed files with 93 additions and 76 deletions

View File

@ -1 +1 @@
6g version weekly.2011-08-10 9382
6g version weekly.2011-08-17 9528+

View File

@ -9,6 +9,7 @@ import (
"log"
"os"
"strings"
"url"
"xml"
"camli/blobref"
@ -200,12 +201,12 @@ func ls(path string) (paths []string) {
}
// TODO(rh) settle on an internal format for paths, and a better way to translate between paths and URLs
func url2path(url *http.URL) string {
return strings.Trim(url.Path, "/") // TODO(rh) make not suck
func url2path(url_ *url.URL) string {
return strings.Trim(url_.Path, "/") // TODO(rh) make not suck
}
func path2url(path string) *http.URL {
return &http.URL{Path: "/" + path} // TODO(rh) make not suck
func path2url(path string) *url.URL {
return &url.URL{Path: "/" + path} // TODO(rh) make not suck
}
func parseprop(x *xmlparser) (props []string) {

View File

@ -2,10 +2,11 @@ package main
import (
"bytes"
"exp/template"
"template"
"fmt"
"http"
"time"
"url"
)
type xmler interface {
@ -15,10 +16,10 @@ type xmler interface {
// See: http://www.webdav.org/specs/rfc4918.html
// 14.7 href XML Element
type href http.URL
type href url.URL
func (h *href) XML(b *bytes.Buffer) {
b.WriteString("<href>" + template.HTMLEscapeString((*http.URL)(h).String()) + "</href>")
b.WriteString("<href>" + template.HTMLEscapeString((*url.URL)(h).String()) + "</href>")
}
// 14.16 multistatus XML Element

View File

@ -23,17 +23,18 @@ import (
"http/httptest"
"os"
"testing"
"url"
)
func makeGetRequest(url string) *http.Request {
func makeGetRequest(url_ string) *http.Request {
req := &http.Request{
Method: "GET",
RawURL: url,
RawURL: url_,
}
var err os.Error
req.URL, err = http.ParseURL(url)
req.URL, err = url.Parse(url_)
if err != nil {
panic("Error parsing url: " + url)
panic("Error parsing url: " + url_)
}
return req
}

View File

@ -80,7 +80,11 @@ func handleMultiPartUpload(conn http.ResponseWriter, req *http.Request, blobRece
break
}
contentDisposition, params := mime.ParseMediaType(mimePart.Header.Get("Content-Disposition"))
contentDisposition, params, err := mime.ParseMediaType(mimePart.Header.Get("Content-Disposition"))
if err != nil {
addError(err.String())
break
}
if contentDisposition != "form-data" {
addError(fmt.Sprintf("Expected Content-Disposition of \"form-data\"; got %q", contentDisposition))
break

View File

@ -18,10 +18,11 @@ package localdisk
import (
"fmt"
"http"
"path/filepath"
"camli/blobref"
"url"
)
func BlobFileBaseName(b *blobref.BlobRef) string {
@ -44,5 +45,5 @@ func (ds *DiskStorage) PartitionRoot(partition string) string {
if partition == "" {
return ds.root
}
return filepath.Join(ds.root, "partition", http.URLEscape(partition))
return filepath.Join(ds.root, "partition", url.QueryEscape(partition))
}

View File

@ -19,8 +19,9 @@ package client
import (
"camli/blobref"
"fmt"
"http"
"os"
"url"
)
type EnumerateOpts struct {
@ -57,9 +58,9 @@ func (c *Client) EnumerateBlobsOpts(ch chan<- blobref.SizedBlobRef, opts Enumera
if after == "" {
waitSec = opts.MaxWaitSec
}
url := fmt.Sprintf("%s/camli/enumerate-blobs?after=%s&limit=%d&maxwaitsec=%d",
c.server, http.URLEscape(after), enumerateBatchSize, waitSec)
req := c.newRequest("GET", url)
url_ := fmt.Sprintf("%s/camli/enumerate-blobs?after=%s&limit=%d&maxwaitsec=%d",
c.server, url.QueryEscape(after), enumerateBatchSize, waitSec)
req := c.newRequest("GET", url_)
resp, err := c.httpClient.Do(req)
if err != nil {
return error("http request", err)

View File

@ -26,6 +26,7 @@ import (
"strings"
"camli/blobref"
"url"
)
type removeResponse struct {
@ -35,8 +36,8 @@ type removeResponse struct {
// Remove the list of blobs. An error is returned if the server failed to
// remove a blob. Removing a non-existent blob isn't an error.
func (c *Client) RemoveBlobs(blobs []*blobref.BlobRef) os.Error {
url := fmt.Sprintf("%s/camli/remove", c.server)
params := make(http.Values) // "blobN" -> BlobRefStr
url_ := fmt.Sprintf("%s/camli/remove", c.server)
params := make(url.Values) // "blobN" -> BlobRefStr
needsDelete := make(map[string]bool) // BlobRefStr -> true
for n, b := range blobs {
if b == nil {
@ -47,7 +48,7 @@ func (c *Client) RemoveBlobs(blobs []*blobref.BlobRef) os.Error {
needsDelete[b.String()] = true
}
req, err := http.NewRequest("POST", url, strings.NewReader(params.Encode()))
req, err := http.NewRequest("POST", url_, strings.NewReader(params.Encode()))
if err != nil {
return fmt.Errorf("Error creating RemoveBlobs POST request: %v", err)
}

View File

@ -29,6 +29,7 @@ import (
"strings"
"camli/blobref"
"url"
)
var _ = log.Printf
@ -237,9 +238,9 @@ func (c *Client) Upload(h *UploadHandle) (*PutResult, os.Error) {
// Pre-upload. Check whether the blob already exists on the
// server and if not, the URL to upload it to.
url := fmt.Sprintf("%s/camli/stat", c.server)
url_ := fmt.Sprintf("%s/camli/stat", c.server)
requestBody := "camliversion=1&blob1=" + blobRefString
req := c.newRequest("POST", url)
req := c.newRequest("POST", url_)
req.Header.Add("Content-Type", "application/x-www-form-urlencoded")
req.Body = ioutil.NopCloser(strings.NewReader(requestBody))
req.ContentLength = int64(len(requestBody))
@ -338,8 +339,8 @@ func (c *Client) Upload(h *UploadHandle) (*PutResult, os.Error) {
if otherLocation == "" {
return errorf("303 without a Location")
}
baseUrl, _ := http.ParseURL(stat.uploadUrl)
absUrl, err := baseUrl.ParseURL(otherLocation)
baseUrl, _ := url.Parse(stat.uploadUrl)
absUrl, err := baseUrl.Parse(otherLocation)
if err != nil {
return errorf("303 Location URL relative resolve error: %v", err)
}

View File

@ -27,6 +27,7 @@ import (
"os"
"strconv"
"strings"
"url"
"xml"
"camli/third_party/code.google.com/goauth2/oauth"
@ -94,9 +95,9 @@ func (gsa *Client) doRequest(req *http.Request, canResend bool) (resp *http.Resp
}
// Makes a simple body-less google storage request
func (gsa *Client) simpleRequest(method, url string) (resp *http.Response, err os.Error) {
func (gsa *Client) simpleRequest(method, url_ string) (resp *http.Response, err os.Error) {
// Construct the request
req, err := http.NewRequest(method, url, nil)
req, err := http.NewRequest(method, url_, nil)
if err != nil {
return
}
@ -206,7 +207,7 @@ func (gsa *Client) EnumerateObjects(bucket, after string, limit uint) ([]SizedOb
// Build url, with query params
params := make([]string, 0, 2)
if after != "" {
params = append(params, "marker="+http.URLEscape(after))
params = append(params, "marker="+url.QueryEscape(after))
}
if limit > 0 {
params = append(params, fmt.Sprintf("max-keys=%v", limit))

View File

@ -27,6 +27,7 @@ import (
"log"
"os"
"strconv"
"url"
"xml"
)
@ -49,8 +50,8 @@ func (c *Client) httpClient() *http.Client {
return http.DefaultClient
}
func newReq(url string) *http.Request {
req, err := http.NewRequest("GET", url, nil)
func newReq(url_ string) *http.Request {
req, err := http.NewRequest("GET", url_, nil)
if err != nil {
panic(fmt.Sprintf("s3 client; invalid URL: %v", err))
}
@ -131,9 +132,9 @@ type listBucketResults struct {
func (c *Client) ListBucket(bucket string, after string, maxKeys uint) (items []*Item, reterr os.Error) {
var bres listBucketResults
url := fmt.Sprintf("http://%s.s3.amazonaws.com/?marker=%s&max-keys=%d",
bucket, http.URLEscape(after), maxKeys)
req := newReq(url)
url_ := fmt.Sprintf("http://%s.s3.amazonaws.com/?marker=%s&max-keys=%d",
bucket, url.QueryEscape(after), maxKeys)
req := newReq(url_)
c.Auth.SignRequest(req)
res, err := c.httpClient().Do(req)
if res != nil && res.Body != nil {
@ -149,8 +150,8 @@ func (c *Client) ListBucket(bucket string, after string, maxKeys uint) (items []
}
func (c *Client) Get(bucket, key string) (body io.ReadCloser, size int64, err os.Error) {
url := fmt.Sprintf("http://%s.s3.amazonaws.com/%s", bucket, key)
req := newReq(url)
url_ := fmt.Sprintf("http://%s.s3.amazonaws.com/%s", bucket, key)
req := newReq(url_)
c.Auth.SignRequest(req)
var res *http.Response
res, err = c.httpClient().Do(req)
@ -174,8 +175,8 @@ func (c *Client) Get(bucket, key string) (body io.ReadCloser, size int64, err os
}
func (c *Client) Delete(bucket, key string) os.Error {
url := fmt.Sprintf("http://%s.s3.amazonaws.com/%s", bucket, key)
req := newReq(url)
url_ := fmt.Sprintf("http://%s.s3.amazonaws.com/%s", bucket, key)
req := newReq(url_)
req.Method = "DELETE"
c.Auth.SignRequest(req)
res, err := c.httpClient().Do(req)

View File

@ -20,11 +20,12 @@ import (
"encoding/hex"
"bufio"
"fmt"
"http"
"net"
"io"
"strings"
"os"
"url"
)
// A connection to the GPG agent.
@ -74,7 +75,7 @@ type PassphraseRequest struct {
}
func (c *Conn) RemoveFromCache(cacheKey string) os.Error {
_, err := fmt.Fprintf(c.c, "CLEAR_PASSPHRASE %s\n", http.URLEscape(cacheKey))
_, err := fmt.Fprintf(c.c, "CLEAR_PASSPHRASE %s\n", url.QueryEscape(cacheKey))
if err != nil {
return err
}
@ -129,12 +130,12 @@ func (c *Conn) GetPassphrase(pr *PassphraseRequest) (passphrase string, outerr o
if s == "" {
return "X"
}
return http.URLEscape(s)
return url.QueryEscape(s)
}
_, err = fmt.Fprintf(c.c, "GET_PASSPHRASE %s%s %s %s %s\n",
opts,
http.URLEscape(pr.CacheKey),
url.QueryEscape(pr.CacheKey),
encOrX(pr.Error),
encOrX(pr.Prompt),
encOrX(pr.Desc))

View File

@ -31,6 +31,7 @@ import (
"camli/blobserver"
"camli/jsonconfig"
"camli/httputil"
"url"
)
const buffered = 32 // arbitrary channel buffer size
@ -75,7 +76,6 @@ func newHandlerFromConfig(ld blobserver.Loader, conf jsonconfig.Obj) (http.Handl
}, nil
}
// TODO: figure out a plan for an owner having multiple active public keys, or public
// key rotation
func (h *Handler) Owner() *blobref.BlobRef {
@ -351,7 +351,6 @@ func (b *DescribedBlob) ContentRef() (br *blobref.BlobRef, ok bool) {
return
}
func (b *DescribedBlob) PeerBlob(br *blobref.BlobRef) *DescribedBlob {
if b.Request == nil {
return &DescribedBlob{BlobRef: br, Stub: true}
@ -410,7 +409,7 @@ func (b *DescribedBlob) jsonMap() map[string]interface{} {
}
type DescribedPermanode struct {
Attr http.Values // a map[string][]string
Attr url.Values // a map[string][]string
}
func (dp *DescribedPermanode) jsonMap() map[string]interface{} {
@ -642,7 +641,7 @@ func (sh *Handler) serveFiles(rw http.ResponseWriter, req *http.Request) {
}
func (dr *DescribeRequest) populatePermanodeFields(pi *DescribedPermanode, pn, signer *blobref.BlobRef, depth int) {
pi.Attr = make(http.Values)
pi.Attr = make(url.Values)
attr := pi.Attr
claims, err := dr.sh.index.GetOwnerClaims(pn, signer)

View File

@ -44,6 +44,7 @@ import (
"json"
"os"
"time"
"url"
)
// Config is the configuration of an OAuth consumer.
@ -106,23 +107,23 @@ func (t *Transport) transport() http.RoundTripper {
// AuthCodeURL returns a URL that the end-user should be redirected to,
// so that they may obtain an authorization code.
func (c *Config) AuthCodeURL(state string) string {
url, err := http.ParseURL(c.AuthURL)
url_, err := url.Parse(c.AuthURL)
if err != nil {
panic("AuthURL malformed: " + err.String())
}
q := http.Values{
q := url.Values{
"response_type": {"code"},
"client_id": {c.ClientId},
"redirect_uri": {c.redirectURL()},
"scope": {c.Scope},
"state": {state},
}.Encode()
if url.RawQuery == "" {
url.RawQuery = q
if url_.RawQuery == "" {
url_.RawQuery = q
} else {
url.RawQuery += "&" + q
url_.RawQuery += "&" + q
}
return url.String()
return url_.String()
}
// Exchange takes a code and gets access Token from the remote server.
@ -131,7 +132,7 @@ func (t *Transport) Exchange(code string) (tok *Token, err os.Error) {
return nil, os.NewError("no Config supplied")
}
tok = new(Token)
err = t.updateToken(tok, http.Values{
err = t.updateToken(tok, url.Values{
"grant_type": {"authorization_code"},
"redirect_uri": {t.redirectURL()},
"scope": {t.Scope},
@ -163,13 +164,13 @@ func (t *Transport) RoundTrip(req *http.Request) (resp *http.Response, err os.Er
}
func (t *Transport) Refresh() os.Error {
return t.updateToken(t.Token, http.Values{
return t.updateToken(t.Token, url.Values{
"grant_type": {"refresh_token"},
"refresh_token": {t.RefreshToken},
})
}
func (t *Transport) updateToken(tok *Token, v http.Values) os.Error {
func (t *Transport) updateToken(tok *Token, v url.Values) os.Error {
v.Set("client_id", t.ClientId)
v.Set("client_secret", t.ClientSecret)
r, err := (&http.Client{Transport: t.transport()}).PostForm(t.TokenURL, v)

View File

@ -9,6 +9,7 @@ import (
"io/ioutil"
"os"
"sort"
"url"
)
const (
@ -113,12 +114,12 @@ func encodeQuery(args map[string]string) string {
s.WriteString("&")
}
i++
s.WriteString(k + "=" + http.URLEscape(v))
s.WriteString(k + "=" + url.QueryEscape(v))
}
return s.String()
}
func (request *Request) buildPost(url string, filename string, filetype string) (*http.Request, os.Error) {
func (request *Request) buildPost(url_ string, filename string, filetype string) (*http.Request, os.Error) {
f, err := os.Open(filename)
if err != nil {
return nil, err
@ -169,7 +170,7 @@ func (request *Request) buildPost(url string, filename string, filetype string)
postRequest := &http.Request{
Method: "POST",
RawURL: url,
RawURL: url_,
Host: apiHost,
Header: http_header,
Body: r,
@ -211,7 +212,7 @@ func (r *Request) sendPost(post *http.Request) (body string, err os.Error) {
}
rawBody, err := ioutil.ReadAll(resp.Body)
if err != nil {
return
}
return
}
return string(rawBody), nil
}

View File

@ -34,6 +34,7 @@ import (
"camli/jsonconfig"
"camli/schema"
"camli/search"
"url"
)
// PublishHandler publishes your info to the world, if permanodes have
@ -251,7 +252,7 @@ func (pr *publishRequest) SubresThumbnailURL(path []*blobref.BlobRef, fileName s
fmt.Fprintf(&buf, "/h%s", br.DigestPrefix(10))
}
fmt.Fprintf(&buf, "/=%s", resType)
fmt.Fprintf(&buf, "/%s", http.URLEscape(fileName))
fmt.Fprintf(&buf, "/%s", url.QueryEscape(fileName))
if maxDimen != -1 {
fmt.Fprintf(&buf, "?mw=%d&mh=%d", maxDimen, maxDimen)
}
@ -393,12 +394,12 @@ func (pr *publishRequest) serveSubject() {
pr.pf(" <link rel='stylesheet' type='text/css' href='%s'>\n", pr.staticPath(filename))
}
for _, filename := range pr.ph.JSFiles {
// TODO(bradfitz): Remove this manual dependency hack once Issue 37 is resolved.
if filename == "camli.js" {
pr.pf(" <script src='%s'></script>\n", pr.staticPath("base64.js"))
pr.pf(" <script src='%s'></script>\n", pr.staticPath("Crypto.js"))
pr.pf(" <script src='%s'></script>\n", pr.staticPath("SHA1.js"))
}
// TODO(bradfitz): Remove this manual dependency hack once Issue 37 is resolved.
if filename == "camli.js" {
pr.pf(" <script src='%s'></script>\n", pr.staticPath("base64.js"))
pr.pf(" <script src='%s'></script>\n", pr.staticPath("Crypto.js"))
pr.pf(" <script src='%s'></script>\n", pr.staticPath("SHA1.js"))
}
pr.pf(" <script src='%s'></script>\n", pr.staticPath(filename))
if filename == "camli.js" && pr.ViewerIsOwner() {
pr.pf(" <script src='%s'></script>\n", pr.base+"?camli.mode=config&cb=onConfiguration")

View File

@ -32,6 +32,7 @@ import (
"camli/jsonconfig"
"camli/search"
uistatic "camlistore.org/server/uistatic"
"url"
)
var _ = log.Printf
@ -144,7 +145,7 @@ func newUiFromConfig(ld blobserver.Loader, conf jsonconfig.Obj) (h http.Handler,
func camliMode(req *http.Request) string {
// TODO-GO: this is too hard to get at the GET Query args on a
// POST request.
m, err := http.ParseQuery(req.URL.RawQuery)
m, err := url.ParseQuery(req.URL.RawQuery)
if err != nil {
return ""
}
@ -254,13 +255,13 @@ func (ui *UIHandler) serveDiscovery(rw http.ResponseWriter, req *http.Request) {
}
discoveryHelper(rw, req, map[string]interface{}{
"blobRoot": ui.BlobRoot,
"searchRoot": ui.SearchRoot,
"jsonSignRoot": ui.JSONSignRoot,
"uploadHelper": "?camli.mode=uploadhelper", // hack; remove with better javascript
"downloadHelper": "./download/",
"blobRoot": ui.BlobRoot,
"searchRoot": ui.SearchRoot,
"jsonSignRoot": ui.JSONSignRoot,
"uploadHelper": "?camli.mode=uploadhelper", // hack; remove with better javascript
"downloadHelper": "./download/",
"directoryHelper": "./tree/",
"publishRoots": pubRoots,
"publishRoots": pubRoots,
})
}
@ -350,8 +351,8 @@ func (ui *UIHandler) serveFileTree(rw http.ResponseWriter, req *http.Request) {
}
fth := &FileTreeHandler{
Fetcher: ui.Storage,
file: blobref,
Fetcher: ui.Storage,
file: blobref,
}
fth.ServeHTTP(rw, req)
}