Skip to content

net/http: sniff.go DetectContentType failing to detect text/html correctly #16275

@turbodonkey

Description

@turbodonkey

Please answer these questions before submitting your issue. Thanks!

  1. What version of Go are you using (go version)?
    go version go1.6.2 darwin/amd64
  2. What operating system and processor architecture are you using (go env)?
    GOARCH="amd64"
    GOBIN=""
    GOEXE=""
    GOHOSTARCH="amd64"
    GOHOSTOS="darwin"
    GOOS="darwin"
    GOPATH=""
    GORACE=""
    GOROOT="/usr/local/go"
    GOTOOLDIR="/usr/local/go/pkg/tool/darwin_amd64"
    GO15VENDOREXPERIMENT="1"
    CC="clang"
    GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fno-common"
    CXX="clang++"
    CGO_ENABLED="1"
  3. What did you do?
package main

import (
    "fmt"
    "net/http"
    "io/ioutil"
)

func main() {
    fp, err := ioutil.ReadFile("test.html")
    if err != nil {
        fmt.Printf("error opening file %s\n", err)
        return
    }
    fmt.Printf("Content-type %s\n", http.DetectContentType(fp))
}

With test.html being:

<!--
this is a dummy comment
-->

<html>
        this is a simple html page
</html>

output: Content-type text/plain; charset=utf-8

  1. What did you expect to see?

output: Content-type text/html; charset=utf-8

Basically DetectContentType should detect the '<!--' at the start of the .html file, and it does not. As soon as I remove the '<!--' tag, then the file is correctly detected as text/html

  1. What did you see instead?

Content-type text/plain; charset=utf-8

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions