Skip to content
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

net/http: problematic content type check #53545

Closed
xepozz opened this issue Jun 24, 2022 · 2 comments
Closed

net/http: problematic content type check #53545

xepozz opened this issue Jun 24, 2022 · 2 comments

Comments

@xepozz
Copy link

xepozz commented Jun 24, 2022

When go http server cannot recognize content type it tries to read 512 bytes from the resource. You can see it here.

It's a dirty cheat.
First of all the resource can be unavailable for further reading.
Secondly if you try to implement your own WebDAV server you need to append or cut part of bytes to fill the buffer right.
Due to code will smell like the following.

if len(f.data) < len(p) {
	// min buffer for http server is 512, so if file is less than one we need to add empty bytes
	missed := len(p) - len(f.data)
	copy(p, append(make([]byte, missed)))
} else {
	copy(p, f.data[:len(p)])
}

Any ideas how to prevent this behaviour?
BTW go hasn't recognized .md and .py files as text/plain type.

@ianlancetaylor ianlancetaylor changed the title frontend/libgo/go/net/http: Dirty content type check net/http: problematic content type check Jun 24, 2022
@ianlancetaylor
Copy link
Contributor

You don't have to supply 512 bytes to satisfy the content type check. You can simply return the bytes available, and then io.EOF.

Go will read the MIME extensions that are defined on your system. You didn't mention what kind of system you are using. Your program can define additional MIME extensions by calling https://pkg.go.dev/mime#AddExtensionType.

I don't see a bug here, and we don't use the issue tracker for questions or discussion, so closing. If you have further questions, please see https://go.dev/wiki/Questions.

@ianlancetaylor ianlancetaylor closed this as not planned Won't fix, can't repro, duplicate, stale Jun 24, 2022
@xepozz
Copy link
Author

xepozz commented Jun 25, 2022

You don't have to supply 512 bytes to satisfy the content type check. You can simply return the bytes available, and then io.EOF.

Thanks, I will try next time.
I'm under MacOS 12.4.

@golang golang locked and limited conversation to collaborators Jun 25, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants