Skip to content

Commit

Permalink
ignore non MIME-type part in Content-Type, such like ;charset=utf8
Browse files Browse the repository at this point in the history
  • Loading branch information
banjun committed Apr 10, 2017
1 parent d5aefea commit 6fbff6f
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions Sources/Generator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ extension APIBlueprintTransition: SwiftConvertible {
"{% endif %}",
" // conver object (Data) to expected type",
" func intercept(object: Any, urlResponse: HTTPURLResponse) throws -> Any {",
" let contentType = urlResponse.allHeaderFields[\"Content-Type\"] as? String",
" let contentType = (urlResponse.allHeaderFields[\"Content-Type\"] as? String)?.components(separatedBy: \";\").first?.trimmingCharacters(in: .whitespaces)",
" switch (object, contentType) {",
" case let (data as Data, \"application/json\"?): return try JSONSerialization.jsonObject(with: data, options: [])",
" case let (data as Data, _): return data",
Expand All @@ -135,7 +135,7 @@ extension APIBlueprintTransition: SwiftConvertible {
" }",
"",
" func response(from object: Any, urlResponse: HTTPURLResponse) throws -> Response {",
" let contentType = urlResponse.allHeaderFields[\"Content-Type\"] as? String",
" let contentType = (urlResponse.allHeaderFields[\"Content-Type\"] as? String)?.components(separatedBy: \";\").first?.trimmingCharacters(in: .whitespaces)",
" switch (urlResponse.statusCode, contentType) {",
"{% for r in responseCases %} case ({{ r.statusCode }}, {{ r.contentType }}):",
" return try .{{ r.case }}({% if r.innerType %}Responses.{% endif %}{{ r.type }}.decodeValue(object))",
Expand Down

0 comments on commit 6fbff6f

Please sign in to comment.