New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
mime/multipart: empty filename leads to loss of part headers #27893
Comments
You can use http.ReadRequest() package main
import (
"bufio"
"fmt"
"log"
"net/http"
"strings"
)
var text = `POST / HTTP/1.1
Content-Length: 730349
Content-Type: multipart/form-data; boundary=adeb81d8e78682facad3ce26db9333753b045e42bd67e0ae18f3cc2284f9
--adeb81d8e78682facad3ce26db9333753b045e42bd67e0ae18f3cc2284f9
Content-Disposition: form-data; name="field"
Content-Type: image/png
some_data_730349
--adeb81d8e78682facad3ce26db9333753b045e42bd67e0ae18f3cc2284f9--
`
func main() {
b := bufio.NewReader(strings.NewReader(text))
req, err := http.ReadRequest(b)
if err != nil {
log.Fatal(err)
}
mr, err := req.MultipartReader()
if err != nil {
log.Fatal(err)
}
for {
part, err := mr.NextPart()
if err != nil {
break
}
fmt.Println(part.Header)
}
} |
@mattn thank you or reply! |
/cc @bradfitz |
See #24041. As far as I know the current 1.11 behavior is consistent with 1.9 and 1.10.4 and all earlier releases (but not 1.10 through 1.10.3). I would very much prefer to not have to change this again. |
I mean if we use Anyway I can deal with it, but it's a standard library, and I think all of us want to use clear interface. |
As far as the part in multipart has not a filename,it should not be called File. So |
Thanks to all. I'm closing the issue. |
What version of Go are you using (
go version
)?1.11
Does this issue reproduce with the latest release?
yes
What operating system and processor architecture are you using (
go env
)?GOARCH="amd64"
GOBIN=""
GOCACHE="/home/alx/.cache/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/alx/go"
GOPROXY=""
GORACE=""
GOROOT="/usr/local/go"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build697396012=/tmp/go-build -gno-record-gcc-switches"
What did you do?
I send form-data part with Content-Type header and without filename parameter.
Due to this fix we lose all headers from part.
What did you expect to see?
I want to get headers from part, so what I can suggest is to introduce method
r.FormHeaders("name") *mutlipart.FileHeader
. This will alow us to preserve originalhttp.Request
interface, and to make part headers accessible.What did you see instead?
Now I can get only form value without headers.
Thank you!
The text was updated successfully, but these errors were encountered: