Migrate from "mime" to "github.com/minio/minio/pkg/mimedb" (#2563)

The content-type resolutions are standardized across platforms.

Fixes #2559
This commit is contained in:
Praveen raj Mani
2018-10-02 17:17:44 -07:00
committed by Dee Koder
parent 7260b0f9ea
commit 449cad0eb8
6 changed files with 4257 additions and 10 deletions
+3 -3
View File
@@ -23,7 +23,6 @@ import (
"encoding/json"
"hash/fnv"
"io"
"mime"
"net"
"net/http"
"net/url"
@@ -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
@@ -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,
+2 -5
View File
@@ -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
@@ -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
}
+2 -2
View File
@@ -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 (
@@ -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"),
+4211
View File
File diff suppressed because it is too large Load Diff
+33
View File
@@ -0,0 +1,33 @@
/*
* mime-db: Mime Database, (C) 2015, 2016, 2017, 2018 Minio, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package mimedb
import (
"strings"
)
// TypeByExtension resolves the extension to its respective content-type.
func TypeByExtension(ext string) string {
// Set default to "application/octet-stream".
var contentType = "application/octet-stream"
if ext != "" {
if content, ok := DB[strings.ToLower(strings.TrimPrefix(ext, "."))]; ok {
contentType = content.ContentType
}
}
return contentType
}
+6
View File
@@ -145,6 +145,12 @@
"revision": "7b274cb618deef62a8f5df2761f2d8431ed71ca7",
"revisionTime": "2018-05-22T01:58:01Z"
},
{
"checksumSHA1": "7zU5IsAQ/H8Utl5s5ihKfezh5Ws=",
"path": "github.com/minio/minio/pkg/mimedb",
"revision": "335a547d7adb4bf9ac0054936dac8bb9edae9fb6",
"revisionTime": "2018-10-01T09:43:49Z"
},
{
"checksumSHA1": "c+s2pYNeuooOUl3tw+4+oNA0hl8=",
"path": "github.com/minio/minio/pkg/quick",