I'd like to know some kind of file checksum (like SHA-256 hash, or anything else) when I start downloading a file from HTTP server. It could be transferred as one of HTTP response headers.
I know http etag is something similar, I think, but this is Golang which I am new to learning and although I have looked through some documentation, I am still clueless. Any help would be appreciated. This is what I have so far:
package main
import (
"flag"
"fmt"
"log"
"net/http"
"strconv"
)
const (
crlf = "
"
colonspace = ": "
)
func Checksum(h http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
func HandleFunc(pattern string, handler func(ResponseWriter, *Request))
})
}
// Do not change this function.
func main() {
var listenAddr = flag.String("http", ":8080", "address to listen on for HTTP")
flag.Parse()
http.Handle("/", Checksum(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("X-Foo", "bar")
w.Header().Set("Content-Type", "text/plain")
w.Header().Set("Date", "Sun, 08 May 2016 14:04:53 GMT")
msg := "Curiosity is insubordination in its purest form.
"
w.Header().Set("Content-Length", strconv.Itoa(len(msg)))
fmt.Fprintf(w, msg)
})))
log.Fatal(http.ListenAndServe(*listenAddr, nil))
}