<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><br class=""><div><blockquote type="cite" class=""><div class="">On Nov 23, 2016, at 2:45 PM, Helge Heß via swift-server-dev &lt;<a href="mailto:swift-server-dev@swift.org" class="">swift-server-dev@swift.org</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class=""><span style="font-family: Helvetica; font-size: 14px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">BTW: It was also mentioned that it may be highly desirable to use Foundation’s NSHTTPURLRequest/NSHTTPResponse.</span><br style="font-family: Helvetica; font-size: 14px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""></div></blockquote></div><br class=""><div class="">A few notes in my head here:&nbsp;</div><div class=""><br class=""></div><div class="">- The NSURL* APIs lack the ability to generate an NSHTTPURLRequest / NSHTTPURLResponse from bytes - the http parser is buried in a CFNetwork API. &nbsp;(I'd like this to change and have an NSHTTPMessage -&gt; NSHTTP(Request | Response)Message available.)</div><div class=""><br class=""></div><div class="">- NSURLResponse is the base class since the NSURL* APis are protocol agnostitic, so the NSURLSession APIs expose this - and everyone casts because in the end, they want an HTTP response. &nbsp;We should avoid this from the get-go.</div><div class=""><br class=""></div><div class="">- The underlying dictionary of (case insensitive) key to value strings of these objects has a major design flaw in that it does not deal with multiple headers with the same key (Set-Cookie) It does this by arbitrarily combining value strings with some deliminter (I think its a ",") The correct API would return a value as an array even if it only contains 1 element.</div><div class=""><br class=""></div><div class="">- The req/resp objects do not preserve parsed header order, which may be desirable. &nbsp;I'm considering adding:</div><div class=""><br class=""></div><div class=""><span class="Apple-tab-span" style="white-space:pre">        </span>-(NSArray *)headerKeyOrder;</div><div class=""><span class="Apple-tab-span" style="white-space:pre">        </span>-(NSArray *)headerValueArrayForKey:(NSString *)key;</div><div class=""><br class=""></div><div class="">- NSURLSession attempts to separate the NSURLRequest API from the existing -bodyData or -bodyStream methods. &nbsp;When performing an upload the bytes of the body may be sent multiple times (in the case where we never receive a response, or the connection closes during an upload, or a proxy is involved) and long ago we had to add a delegate to request a new body stream. &nbsp;The NSURLSession async convenience APIs work with data and stream objects external to the NSURLRequest, and in the stream case always defer to the delegate for an upload stream if data was not provided. &nbsp;This separation of header and body is consistent with an NSURLResponse being distinct from the received data. &nbsp;(Always requiring a stream be provided by a delegate guarantees that developers implement the method correctly so they continue to work in the edge cases that they can never actually test with!)</div><div class=""><br class=""></div><div class=""><div class="">- NSHTTPURLRequest and NSHTTPURLResponse mutability is an issue that just makes for a messy API. &nbsp;Making these value classes makes sense - the headers are never large enough to warrant even COW semantics for the internal dictionary.</div></div><div class=""><br class=""></div><div class="">- The client headers are not complete until they're about to be put on the wire; the URL of a request is added as a Host: very late and it is not possible to see the entire header before it is sent. (This is a limitation of the NSURLSession / NSURLConnection APIs as it necessarily involved a delegate callout and subsequent performance hit.). This may be true of a server API as well, where configuration options from the server are added immediately before the response is written.</div><div class=""><br class=""></div><div class="">--sma</div><div class=""><br class=""></div></body></html>