http2: fix two cases of Server behavior not matching HTTP/1

* don't send automatic Content-Length from Server on HEAD requests if
  response size is 0 (it's possible the handler didn't write because
  they looked at the method)

* don't send Content-Type if handler explicitly set it to nothing.

Matches the behavior of HTTP/1.

Updates golang/go#13532
Updates golang/go#13495

Change-Id: If6e0898095cf88cb14efb6bbe82c88dbc2077e6b
Reviewed-on: https://go-review.googlesource.com/17590
Reviewed-by: Blake Mizerany <blake.mizerany@gmail.com>
diff --git a/http2/server.go b/http2/server.go
index 8ef9e24..992e546 100644
--- a/http2/server.go
+++ b/http2/server.go
@@ -1758,10 +1758,11 @@
 				clen = ""
 			}
 		}
-		if clen == "" && rws.handlerDone && bodyAllowedForStatus(rws.status) {
+		if clen == "" && rws.handlerDone && bodyAllowedForStatus(rws.status) && (len(p) > 0 || !isHeadResp) {
 			clen = strconv.Itoa(len(p))
 		}
-		if rws.snapHeader.Get("Content-Type") == "" && bodyAllowedForStatus(rws.status) {
+		_, hasContentType := rws.snapHeader["Content-Type"]
+		if !hasContentType && bodyAllowedForStatus(rws.status) {
 			ctype = http.DetectContentType(p)
 		}
 		var date string