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