Skip to content

Commit

Permalink
Migrate from "mime" to "github.com/minio/minio/pkg/mimedb"
Browse files Browse the repository at this point in the history
The content-type resolutions are standardized across platforms.

Fixes #2559
  • Loading branch information
Praveenrajmani committed Oct 2, 2018
1 parent a83ffe3 commit 01297f5
Show file tree
Hide file tree
Showing 6 changed files with 4,257 additions and 10 deletions.
6 changes: 3 additions & 3 deletions cmd/client-s3.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import (
"encoding/json"
"hash/fnv"
"io"
"mime"
"net"
"net/http"
"net/url"
Expand All @@ -42,6 +41,7 @@ import (
"github.com/minio/minio-go/pkg/encrypt"
"github.com/minio/minio-go/pkg/policy"
"github.com/minio/minio-go/pkg/s3utils"
"github.com/minio/minio/pkg/mimedb"
)

// S3 client
Expand Down Expand Up @@ -396,8 +396,8 @@ var supportedContentTypes = []string{

func (c *s3Client) Select(expression, sseKey string) (io.ReadCloser, *probe.Error) {
bucket, object := c.url2BucketAndObject()
origContentType := mime.TypeByExtension(filepath.Ext(strings.TrimSuffix(strings.TrimSuffix(object, ".gz"), ".bz2")))
contentType := mime.TypeByExtension(filepath.Ext(object))
origContentType := mimedb.TypeByExtension(filepath.Ext(strings.TrimSuffix(strings.TrimSuffix(object, ".gz"), ".bz2")))
contentType := mimedb.TypeByExtension(filepath.Ext(object))
opts := minio.SelectObjectOptions{
Expression: expression,
ExpressionType: minio.QueryExpressionTypeSQL,
Expand Down
7 changes: 2 additions & 5 deletions cmd/client-url.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ package cmd

import (
"bytes"
"mime"
"path/filepath"
"regexp"
"runtime"
"strings"

"github.com/minio/mc/pkg/probe"
"github.com/minio/minio/pkg/mimedb"
)

// url client url structure
Expand Down Expand Up @@ -228,9 +228,6 @@ func isURLPrefixExists(urlPrefix string, incomplete bool) bool {
// on failure just return 'application/octet-stream'.
func guessURLContentType(urlStr string) string {
url := newClientURL(urlStr)
contentType := mime.TypeByExtension(filepath.Ext(url.Path))
if contentType == "" {
contentType = "application/octet-stream"
}
contentType := mimedb.TypeByExtension(filepath.Ext(url.Path))
return contentType
}
4 changes: 2 additions & 2 deletions cmd/select-main.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ package cmd

import (
"io"
"mime"
"os"
"path/filepath"
"strings"

"github.com/minio/cli"
"github.com/minio/mc/pkg/probe"
"github.com/minio/minio/pkg/mimedb"
)

var (
Expand Down Expand Up @@ -130,7 +130,7 @@ func mainSelect(ctx *cli.Context) error {
errorIf(content.Err.Trace(url), "Unable to list on target `"+url+"`.")
continue
}
contentType := mime.TypeByExtension(filepath.Ext(content.URL.Path))
contentType := mimedb.TypeByExtension(filepath.Ext(content.URL.Path))
for _, cTypeSuffix := range supportedContentTypes {
if strings.Contains(contentType, cTypeSuffix) {
errorIf(selectQl(targetAlias+content.URL.Path, ctx.String("expression"),
Expand Down
Loading

0 comments on commit 01297f5

Please sign in to comment.