Exemplo n.º 1
0
func stdinReader() {
	defer close(urls)

	stdinReader := bufio.NewReader(os.Stdin)
	for {
		line, read_err := stdinReader.ReadBytes('\n')
		if read_err != nil && read_err != os.EOF {
			panic("At ReadBytes")
			return
		}

		line = bytes.TrimSpace(line)
		if len(line) == 0 {
			goto Next
		}

		url, err := http.ParseURLReference(string(line))
		if err != nil {
			result := ErrorResult(string(line), err.String())
			report_json, _ := encodeResult(result)
			reports <- report_json
		} else {
			urls <- url
		}

	Next:
		if read_err == os.EOF {
			return
		}
	}
}
Exemplo n.º 2
0
func updateWidget(w http.ResponseWriter, r *http.Request) {
	var err os.Error
	ctx := appengine.NewContext(r)

	fix := func(formname string) string {
		raw := r.FormValue(formname)
		if strings.Contains(raw, "'") {
			ctx.Warningf("Hacking attempt: %#q", raw)
			return ""
		}
		url, err := http.ParseURLReference(raw)
		if err != nil {
			ctx.Infof("Bad URL: %#q", raw)
			return ""
		}
		if scheme := strings.ToLower(url.Scheme); scheme != "http" && scheme != "https" {
			ctx.Infof("Bad scheme: %%q", scheme)
			return ""
		}
		return url.String()
	}

	bug := fix("bug")
	home := fix("home")
	source := fix("source")

	path := strings.Split(strings.Trim(r.URL.Path, "/"), "/", -1)
	if cnt := len(path); cnt != 3 {
		http.Error(w, "ID required", http.StatusBadRequest)
		return
	}

	widgethash := path[2]
	if len(widgethash) != 32 {
		http.Error(w, "Invalid widget id: "+widgethash, http.StatusBadRequest)
		return
	}

	widget, err := LoadWidget(ctx, widgethash)
	if err != nil {
		http.Error(w, "Unknown widget id: "+widgethash, http.StatusBadRequest)
		return
	}

	widget.BugURL = bug
	widget.HomeURL = home
	widget.SourceURL = source

	err = widget.Commit()
	if err != nil {
		http.Error(w, "Error comitting: "+err.String(), http.StatusBadRequest)
		return
	}

	http.Redirect(w, r, "/widget/list", http.StatusFound)
}
Exemplo n.º 3
0
// Connect to the database specified by dsn.
func Connect(dsn string) (Connection, os.Error) {
	url, err := http.ParseURLReference(dsn)
	if err != nil {
		return nil, os.NewError("Invalid DSN URL: " + dsn)
	}
	driver, found := drivers[url.Scheme]
	if !found {
		return nil, os.NewError("No driver found: " + url.Scheme)
	}
	return driver.Connect(url)
}
Exemplo n.º 4
0
// return an http.Request equivalent to r
func (r *request) getHttpRequest() *http.Request {
	h := &http.Request{
		Method: r.params["REQUEST_METHOD"],
		RawURL: r.params["REQUEST_URI"],
		Proto:  r.params["SERVER_PROTOCOL"],
		Close:  r.close,
		Body:   nopCloser{Reader: r.stdin},
		Header: map[string]string{},
	}
	if h.Proto[0:4] != "HTTP" {
		return nil
	}
	i := 5
	h.ProtoMajor, i, _ = atoi(h.Proto, i)
	h.ProtoMinor, _, _ = atoi(h.Proto, i+1)
	if url, err := http.ParseURLReference("http://" + r.params["HTTP_HOST"] + r.params["REQUEST_URI"] + "?" + r.params["QUERY_STRING"]); err == nil {
		h.URL = url
	}
	if host, ok := r.params["HTTP_HOST"]; ok {
		h.Host = host
	}
	if ref, ok := r.params["HTTP_REFERER"]; ok {
		h.Referer = ref
	}
	if agent, ok := r.params["HTTP_USER_AGENT"]; ok {
		h.UserAgent = agent
	}
	for key, val := range r.params {
		if strings.HasPrefix(key, "HTTP_") {
			h.Header[standardCase(key[5:])] = val
		}
		if strings.HasPrefix(key, "SERVER_") {
			h.Header[standardCase(key)] = val
		}
	}
	return h
}