Skip to content

Commit

Permalink
fixed bug with no content type
Browse files Browse the repository at this point in the history
  • Loading branch information
dileping committed Mar 7, 2016
1 parent f27c61f commit d7d93c1
Showing 1 changed file with 4 additions and 10 deletions.
14 changes: 4 additions & 10 deletions Express/Response.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import BrightFutures
//TODO: refactor
protocol HeadersAdjuster {
typealias Content : FlushableContentType
static func adjustHeaders(headers:Dictionary<String, String>, c:Content?) -> Dictionary<String, String>
static func adjustHeaders(headers:Dictionary<String, String>, c:ContentType?) -> Dictionary<String, String>
}

public protocol ResponseType : HttpResponseHeadType {
Expand All @@ -35,18 +35,15 @@ public protocol ResponseType : HttpResponseHeadType {
public class Response<C : FlushableContentType> : HttpResponseHead, HeadersAdjuster, ResponseType {
typealias Content = C

/// swift limitation
public let typesafeContent:C?
public let content:FlushableContentType?

public convenience init(status:StatusCode, content:C? = nil, headers:Dictionary<String, String> = Dictionary()) {
self.init(status: status.rawValue, content: content, headers: headers)
}

public init(status:UInt16, content:C? = nil, headers:Dictionary<String, String> = Dictionary()) {
self.typesafeContent = content
self.content = content
super.init(status: status, headers:Response<C>.adjustHeaders(headers, c: typesafeContent))
super.init(status: status, headers:Response<C>.adjustHeaders(headers, c: content))
}

public override func flushTo(out:DataConsumerType) -> Future<Void, AnyError> {
Expand All @@ -63,12 +60,9 @@ public class Response<C : FlushableContentType> : HttpResponseHead, HeadersAdjus
}
}

static func adjustHeaders(headers:Dictionary<String, String>, c:Content?) -> Dictionary<String, String> {
static func adjustHeaders(headers:Dictionary<String, String>, c:ContentType?) -> Dictionary<String, String> {
let cType:String? = c.flatMap { content in
switch content {
case let ac as AnyContent: return ac.contentType
default: return nil
}
content.contentType
}
let h:Dictionary<String, String>? = cType.map { ct in
var mHeaders = headers
Expand Down

0 comments on commit d7d93c1

Please sign in to comment.