Gerrit Bot has uploaded this change for review.
net/http: mention io.Seeker requirement in FS documentation
Both FileServer and NewFileTransport can try to seek a file, specifically when
MIME type sniffing is performed. This can be somewhat surprising to an
implementer of an fs.FS, as their filesystem will appear to work until a user
tries to access a file with an unrecognized extension (which requires type
sniffing and therefore seeking). With FileServer, this results in a "seeker
can't seek" message, which is not very clear for the developer.
The issue arises because fs.FS does not require Seek, while http.FileSystem
does. Therefore, this change adds a line to the documentation of net/http's
adapter function mentioning the requirement.
Change-Id: Ieb955b7a7f34e2be39dd696cb712513c70100b3a
GitHub-Last-Rev: 319a4d9d5aa2a4718e7bf9514d116f1884f04cf2
GitHub-Pull-Request: golang/go#48781
---
M src/net/http/fs.go
1 file changed, 24 insertions(+), 0 deletions(-)
diff --git a/src/net/http/fs.go b/src/net/http/fs.go
index 57e731e..6aa68c3 100644
--- a/src/net/http/fs.go
+++ b/src/net/http/fs.go
@@ -815,6 +815,8 @@
// FS converts fsys to a FileSystem implementation,
// for use with FileServer and NewFileTransport.
+// The files provided by fsys must implement io.Seeker
+// for full compatibility with FileServer and NewFileTransport.
func FS(fsys fs.FS) FileSystem {
return ioFS{fsys}
}
To view, visit change 353874. To unsubscribe, or for help writing mail filters, visit settings.
Attention is currently required from: Damien Neil.
Gerrit Bot uploaded patch set #2 to this change.
net/http: mention io.Seeker requirement in FS documentation
net/http: mention io.Seeker requirement in FS documentation
Both FileServer and NewFileTransport can try to seek a file, specifically
when MIME type sniffing is performed. This can be somewhat surprising to an
implementer of an fs.FS, as their filesystem will appear to work until a
user tries to access a file with an unrecognized extension (which requires
type sniffing and therefore seeking). With FileServer, this results in a
"seeker can't seek" message, which is not very clear for the developer.
The issue arises because fs.FS does not require Seek, while http.FileSystem
does. Therefore, this change adds a line to the documentation of net/http's
adapter function mentioning the requirement.
Change-Id: Ieb955b7a7f34e2be39dd696cb712513c70100b3a
GitHub-Last-Rev: 655be81eec59d292fa8a0dd136840a4467c178b5
GitHub-Pull-Request: golang/go#48781
---
M src/net/http/fs.go
1 file changed, 26 insertions(+), 0 deletions(-)
To view, visit change 353874. To unsubscribe, or for help writing mail filters, visit settings.
Attention is currently required from: Damien Neil.
Gerrit Bot uploaded patch set #3 to this change.
net/http: mention io.Seeker requirement in FS documentation
Both FileServer and NewFileTransport can try to seek a file, specifically
when MIME type sniffing is performed. This can be somewhat surprising to an
implementer of an fs.FS, as their filesystem will appear to work until a
user tries to access a file with an unrecognized extension (which requires
type sniffing and therefore seeking). With FileServer, this results in a
"seeker can't seek" message, which is not very clear for the developer.
The issue arises because fs.FS does not require Seek, while http.FileSystem
does. Therefore, this change adds a line to the documentation of net/http's
adapter function mentioning the requirement.
Change-Id: Ieb955b7a7f34e2be39dd696cb712513c70100b3a
GitHub-Last-Rev: 655be81eec59d292fa8a0dd136840a4467c178b5
GitHub-Pull-Request: golang/go#48781
---
M src/net/http/fs.go
1 file changed, 24 insertions(+), 0 deletions(-)
To view, visit change 353874. To unsubscribe, or for help writing mail filters, visit settings.
Patch set 3:Trust +1
1 comment:
File src/net/http/fs.go:
Patch Set #3, Line 819: // for full compatibility with FileServer and NewFileTransport.
How about just:
// The files provided by fsys must implement io.Seeker.
(ServeContent does document that "the content's Seek method must work", but an additional note here seems reasonable.)
To view, visit change 353874. To unsubscribe, or for help writing mail filters, visit settings.
Gerrit Bot uploaded patch set #4 to this change.
net/http: mention io.Seeker requirement in FS documentation
Both FileServer and NewFileTransport can try to seek a file, specifically
when MIME type sniffing is performed. This can be somewhat surprising to an
implementer of an fs.FS, as their filesystem will appear to work until a
user tries to access a file with an unrecognized extension (which requires
type sniffing and therefore seeking). With FileServer, this results in a
"seeker can't seek" message, which is not very clear for the developer.
The issue arises because fs.FS does not require Seek, while http.FileSystem
does. Therefore, this change adds a line to the documentation of net/http's
adapter function mentioning the requirement.
Change-Id: Ieb955b7a7f34e2be39dd696cb712513c70100b3a
GitHub-Last-Rev: 56d2d41bc9347c45a17db2dfa68dd32b62368d16
GitHub-Pull-Request: golang/go#48781
---
M src/net/http/fs.go
1 file changed, 23 insertions(+), 0 deletions(-)
To view, visit change 353874. To unsubscribe, or for help writing mail filters, visit settings.
Attention is currently required from: Damien Neil.
2 comments:
Patchset:
That makes sense to me, done!
File src/net/http/fs.go:
Patch Set #3, Line 819: // for full compatibility with FileServer and NewFileTransport.
How about just: […]
Done
To view, visit change 353874. To unsubscribe, or for help writing mail filters, visit settings.
Patch set 4:Run-TryBot +1Code-Review +2Trust +1
Patch set 4:Trust +1
Gerrit Bot uploaded patch set #5 to this change.
net/http: mention io.Seeker requirement in FS documentation
Both FileServer and NewFileTransport can try to seek a file, specifically
when MIME type sniffing is performed. This can be somewhat surprising to an
implementer of an fs.FS, as their filesystem will appear to work until a
user tries to access a file with an unrecognized extension (which requires
type sniffing and therefore seeking). With FileServer, this results in a
"seeker can't seek" message, which is not very clear for the developer.
The issue arises because fs.FS does not require Seek, while http.FileSystem
does. Therefore, this change adds a line to the documentation of net/http's
adapter function mentioning the requirement.
Change-Id: Ieb955b7a7f34e2be39dd696cb712513c70100b3a
GitHub-Last-Rev: fddccdae36e04fcb87d78b3b03fa4658dbb7d83d
GitHub-Pull-Request: golang/go#48781
---
M src/net/http/fs.go
1 file changed, 23 insertions(+), 0 deletions(-)
To view, visit change 353874. To unsubscribe, or for help writing mail filters, visit settings.
Patch set 5:Run-TryBot +1
Damien Neil removed a vote from this change.
To view, visit change 353874. To unsubscribe, or for help writing mail filters, visit settings.
Attention is currently required from: Ian Lance Taylor, hopehook.
Patch set 6:Run-TryBot +1Auto-Submit +1Code-Review +2
Attention is currently required from: Damien Neil, Ian Lance Taylor, hopehook.
Patch set 6:Code-Review +1
Attention is currently required from: Damien Neil, Ian Lance Taylor, hopehook.
Patch set 6:Code-Review +2
Gopher Robot submitted this change.
net/http: mention io.Seeker requirement in FS documentation
Both FileServer and NewFileTransport can try to seek a file, specifically
when MIME type sniffing is performed. This can be somewhat surprising to an
implementer of an fs.FS, as their filesystem will appear to work until a
user tries to access a file with an unrecognized extension (which requires
type sniffing and therefore seeking). With FileServer, this results in a
"seeker can't seek" message, which is not very clear for the developer.
The issue arises because fs.FS does not require Seek, while http.FileSystem
does. Therefore, this change adds a line to the documentation of net/http's
adapter function mentioning the requirement.
Change-Id: Ieb955b7a7f34e2be39dd696cb712513c70100b3a
GitHub-Last-Rev: fddccdae36e04fcb87d78b3b03fa4658dbb7d83d
GitHub-Pull-Request: golang/go#48781
Reviewed-on: https://go-review.googlesource.com/c/go/+/353874
Reviewed-by: Damien Neil <dn...@google.com>
Auto-Submit: Damien Neil <dn...@google.com>
Run-TryBot: Damien Neil <dn...@google.com>
TryBot-Result: Gopher Robot <go...@golang.org>
Reviewed-by: David Chase <drc...@google.com>
---
M src/net/http/fs.go
1 file changed, 29 insertions(+), 0 deletions(-)
diff --git a/src/net/http/fs.go b/src/net/http/fs.go
index 4f144eb..87caeb7 100644
--- a/src/net/http/fs.go
+++ b/src/net/http/fs.go
@@ -818,6 +818,7 @@
// FS converts fsys to a FileSystem implementation,
// for use with FileServer and NewFileTransport.
+// The files provided by fsys must implement io.Seeker.
func FS(fsys fs.FS) FileSystem {
return ioFS{fsys}
}
To view, visit change 353874. To unsubscribe, or for help writing mail filters, visit settings.