本站源代码
Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

46 lines
1.1KB

  1. // Copyright 2015 go-swagger maintainers
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. package runtime
  15. import (
  16. "mime"
  17. "net/http"
  18. "github.com/go-openapi/errors"
  19. )
  20. // ContentType parses a content type header
  21. func ContentType(headers http.Header) (string, string, error) {
  22. ct := headers.Get(HeaderContentType)
  23. orig := ct
  24. if ct == "" {
  25. ct = DefaultMime
  26. }
  27. if ct == "" {
  28. return "", "", nil
  29. }
  30. mt, opts, err := mime.ParseMediaType(ct)
  31. if err != nil {
  32. return "", "", errors.NewParseError(HeaderContentType, "header", orig, err)
  33. }
  34. if cs, ok := opts[charsetKey]; ok {
  35. return mt, cs, nil
  36. }
  37. return mt, "", nil
  38. }
上海开阖软件有限公司 沪ICP备12045867号-1