// HashHandler parses a POST request, gets and returns the first 1024 bytes.
HashHandler parses a POST request, gets and returns the first 1024 bytes.
// HashHandler parses a POST request gets and returns the first 1024 bytes .
func HashHandler(w http.ResponseWriter, r *http.Request) {
	domain := getDomain(r)
	log.Printf("POST: %s /%s %s - %s",
		domain,
		r.RemoteAddr,
		r.Host,
		r.UserAgent())
	r.ParseForm()
	sigurl, err := url.Parse(r.FormValue("url"))
	if err != nil {
		log.Println("errrrr")
		log.Println(err)
		return
	}
	if len(sigurl.String()) > maxurlsize {
		log.Println("Too long.")
		log.Println(len(sigurl.String()), " > ", maxurlsize)
		return
	}
	log.Println("Grabbing", sigurl)
	zr := &http.Request{
		Method: "GET",
		URL:    sigurl,
		Header: http.Header{
			"User-Agent": {"checksigd/0.1"},
		},
	}
	resp, err := apigun.Do(zr)
	if err != nil {
		log.Println(err)
		return
	}
	if http.CanonicalHeaderKey(resp.Header.Get("content-type")) != text {
		log.Printf("Not giving it! %s != %s", http.CanonicalHeaderKey(resp.Header.Get("content-type")), text)
		return
	} else {
		log.Println("Looks good!")
	}
	resp.Body = http.MaxBytesReader(w, resp.Body, maxbytes)
	out := io.LimitReader(resp.Body, maxbytes)
	if _, err := io.Copy(w, out); err != nil {
		log.Println(err)
		return
	}
	log.Println("Gave signature.")
	return
}
func HashHandler ( w http . ResponseWriter , r * http . Request ) { domain := getDomain ( r ) log . Printf ( " " , domain , r . RemoteAddr , r . Host , r . UserAgent ( ) ) r . ParseForm ( ) sigurl , err := url . Parse ( r . FormValue ( " " ) ) if err != nil { log . Println ( " " ) log . Println ( err ) return } if len ( sigurl . String ( ) ) > maxurlsize { log . Println ( " " ) log . Println ( len ( sigurl . String ( ) ) , " " , maxurlsize ) return } log . Println ( " " , sigurl ) zr := & http . Request { Method : " " , URL : sigurl , Header : http . Header { " " : { " " } , } , } resp , err := apigun . Do ( zr ) if err != nil { log . Println ( err ) return } if http . CanonicalHeaderKey ( resp . Header . Get ( " " ) ) != text { log . Printf ( " " , http . CanonicalHeaderKey ( resp . Header . Get ( " " ) ) , text ) return } else { log . Println ( " " ) } resp . Body = http . MaxBytesReader ( w , resp . Body , maxbytes ) out := io . LimitReader ( resp . Body , maxbytes ) if _ , err := io . Copy ( w , out ) ; err != nil { log . Println ( err ) return } log . Println ( " " ) return }
HashHandler parses a POST request, gets and returns the first 1024 bytes.
HashHandler parses a POST request gets and returns the first 1024 bytes .
// Send the rest to /dev/null //log.Println(io.Copy(ioutil.Discard, r.Body)) // todo: This should be equal to the domain name advertised. // Log the request // Parse the user's request. // Typical request: // curl -d url=<http://example.com/md5.txt> https://checksigd.example.org //	if r.FormValue("url") != "" { // Check if it is a URL // todo: // log.Println("Asking peers") // askpeers(r.FormValue("url")) // Create http request to send // Limit to 1MiB //	zr.Body = http.MaxBytesReader(w, zr.Body, 1024) // Send request to alien server // Log header // log.Println(resp.Header) // Check content-type header var for text/plain // Limit grab into mem // Limit our response // Copy bytes from temporary buffer to browser/curl // If we made it this far, we ran into no problems. //	} //	fmt.Fprintf(w, "yo dawg, you were tryin to check the hash...\n")