]> go.fuhry.dev Git - runtime.git/commitdiff
[http] fix s3 chunk size workaround, enable H2 ALPN
authorDan Fuhry <dan@fuhry.com>
Tue, 8 Jul 2025 14:30:07 +0000 (10:30 -0400)
committerDan Fuhry <dan@fuhry.com>
Tue, 8 Jul 2025 14:34:46 +0000 (10:34 -0400)
- Set `NextProtos` to `[]string{"h2"}` when setting up tls config for http server
- Use `io.CopyN` to stream response in route_action_s3

http/route_action_s3.go
http/server.go

index 49bf85b88bdc7e507db0aea87d2831182b14b59b..7cabce6e258dc20be5077d397389249f8fd12190 100644 (file)
@@ -4,7 +4,6 @@ import (
        "fmt"
        "io"
        "net/http"
-       "strconv"
        "strings"
        "sync"
 
@@ -56,46 +55,17 @@ func (a *S3Action) Handle(w http.ResponseWriter, r *http.Request, next http.Hand
 
        stat, err := object.Stat()
        if err != nil {
-               w.WriteHeader(http.StatusInternalServerError)
+               er := minio.ToErrorResponse(err)
+               w.WriteHeader(er.StatusCode)
                w.Write([]byte(fmt.Sprintf("failed to stat object %q: %+v", objPath, err)))
                return
        }
 
        w.Header().Set("content-type", stat.ContentType)
+       w.Header().Set("content-length", fmt.Sprintf("%d", stat.Size))
        w.WriteHeader(http.StatusOK)
 
-       if strings.HasPrefix(stat.ContentType, "text/") || strings.HasPrefix(stat.ContentType, "application/") {
-               buf := make([]byte, 32*1024)
-               var out []byte
-               for {
-                       nr, err := object.Read(buf)
-                       if nr == 0 && err != nil {
-                               break
-                       }
-                       end := nr
-                       for i := nr; i > 0; i-- {
-                               if buf[i-1] != '\000' {
-                                       end = i
-                                       break
-                               }
-                       }
-                       out = append(out, buf[:end]...)
-
-                       if err == io.EOF {
-                               break
-                       }
-               }
-               w.Header().Set("content-length", strconv.Itoa(len(out)))
-               for nw := 0; nw < len(out); {
-                       c, err := w.Write(out[nw:])
-                       if err != nil {
-                               break
-                       }
-                       nw += c
-               }
-       } else {
-               io.Copy(w, object)
-       }
+       io.CopyN(w, object, stat.Size)
 }
 
 func (a *S3Action) minioClient() (mc *minio.Client, err error) {
index 41afc7f67db95b85cddbbba69c9352c01a74cc1d..eb52e7262e762a698297a92147b5131bb5ddade8 100644 (file)
@@ -250,6 +250,7 @@ func (l *Listener) NewHTTPServerWithContext(ctx context.Context) (*http.Server,
                if err != nil {
                        return nil, err
                }
+               tlsConfig.NextProtos = []string{"h2"}
                server.TLSConfig = tlsConfig
        }