2015-02-15 03:48:15 -05:00
|
|
|
/*
|
2015-07-24 20:51:40 -04:00
|
|
|
* Minio Cloud Storage, (C) 2015 Minio, Inc.
|
2015-02-15 03:48:15 -05:00
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
2015-09-19 03:52:01 -04:00
|
|
|
package main
|
2015-02-11 06:23:15 -05:00
|
|
|
|
2015-04-22 19:28:23 -04:00
|
|
|
import "net/http"
|
2015-02-11 06:23:15 -05:00
|
|
|
|
|
|
|
type contentType int
|
|
|
|
|
|
|
|
const (
|
2015-04-22 19:28:13 -04:00
|
|
|
unknownContentType contentType = iota
|
|
|
|
xmlContentType
|
2015-03-28 21:00:55 -04:00
|
|
|
jsonContentType
|
2015-02-11 06:23:15 -05:00
|
|
|
)
|
|
|
|
|
2015-02-23 19:46:48 -05:00
|
|
|
// Get content type requested from 'Accept' header
|
2015-02-11 06:23:15 -05:00
|
|
|
func getContentType(req *http.Request) contentType {
|
2015-03-28 21:00:55 -04:00
|
|
|
acceptHeader := req.Header.Get("Accept")
|
2015-04-22 22:29:39 -04:00
|
|
|
switch {
|
|
|
|
case acceptHeader == "application/json":
|
|
|
|
return jsonContentType
|
|
|
|
default:
|
|
|
|
return xmlContentType
|
2015-02-11 06:23:15 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-02-23 19:46:48 -05:00
|
|
|
// Content type to human readable string
|
2015-03-28 21:00:55 -04:00
|
|
|
func getContentTypeString(content contentType) string {
|
|
|
|
switch content {
|
|
|
|
case jsonContentType:
|
|
|
|
{
|
|
|
|
return "application/json"
|
|
|
|
}
|
2015-04-22 19:28:13 -04:00
|
|
|
case xmlContentType:
|
|
|
|
{
|
|
|
|
return "application/xml"
|
|
|
|
}
|
2015-03-28 21:00:55 -04:00
|
|
|
default:
|
|
|
|
{
|
|
|
|
return "application/xml"
|
|
|
|
}
|
|
|
|
}
|
2015-02-11 06:23:15 -05:00
|
|
|
}
|