Skip to content

Commit e0dc8c8

Browse files
committed
Don't let libcurl handle Location headers.
1 parent 35b6f5f commit e0dc8c8

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

Foundation/NSURLSession+libcurl.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -975,6 +975,10 @@ extension NSURLSessionTask.EasyHandle {
975975
func setPassHeadersToDataStream(flag: Bool) {
976976
try! CFURLSession_easy_setopt_long(rawHandle, CFURLSession_OptionHEADER, flag ? 1 : 0).asError()
977977
}
978+
/// Follow any Location: header that the server sends as part of a HTTP header in a 3xx response
979+
func setFollowLocation(flag: Bool) {
980+
try! CFURLSession_easy_setopt_long(rawHandle, CFURLSession_OptionFOLLOWLOCATION, flag ? 1 : 0).asError()
981+
}
978982
/// Switch off the progress meter. It will also prevent the CFURLSession_OptionPROGRESSFUNCTION from getting called.
979983
func setProgressMeterOff(flag: Bool) {
980984
try! CFURLSession_easy_setopt_long(rawHandle, CFURLSession_OptionNOPROGRESS, flag ? 1 : 0).asError()
@@ -1144,6 +1148,8 @@ private extension NSURLSessionTask.EasyHandle {
11441148
return NSURLErrorNetworkConnectionLost
11451149
case (CFURLSession_EasyCodeSEND_ERROR, ECONNRESET):
11461150
return NSURLErrorNetworkConnectionLost
1151+
case (CFURLSession_EasyCodeGOT_NOTHING, _):
1152+
return NSURLErrorBadServerResponse
11471153
default:
11481154
//TODO: Need to map to one of the NSURLError... constants
11491155
NSUnimplemented()

Foundation/NSURLSession.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -840,6 +840,9 @@ private extension NSURLSessionTask {
840840
//
841841
// The `HTTPBody` and `HTTPBodyStream` methods are missing from `NSURLRequest` ?!?
842842
}
843+
844+
// HTTP Options:
845+
easyHandle.setFollowLocation(false)
843846
easyHandle.setCustomHeaders([]) //TODO: Fix headers
844847
easyHandle.setDisableContentDecoding()
845848
easyHandle.setWaitForPipeliningAndMultiplexing(true)

0 commit comments

Comments
 (0)