Skip to content

Basic NSURLRequest initialization, getters and tests #73

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Dec 9, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Foundation.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@
84BA558E1C16F90900F48C54 /* TestNSTimeZone.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84BA558D1C16F90900F48C54 /* TestNSTimeZone.swift */; };
C93559291C12C49F009FD6A9 /* TestNSAffineTransform.swift in Sources */ = {isa = PBXBuildFile; fileRef = C93559281C12C49F009FD6A9 /* TestNSAffineTransform.swift */; };
DCDBB8331C1768AC00313299 /* TestNSData.swift in Sources */ = {isa = PBXBuildFile; fileRef = DCDBB8321C1768AC00313299 /* TestNSData.swift */; };
83712C8E1C1684900049AD49 /* TestNSURLRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 83712C8D1C1684900049AD49 /* TestNSURLRequest.swift */; };
E876A73E1C1180E000F279EC /* TestNSRange.swift in Sources */ = {isa = PBXBuildFile; fileRef = E876A73D1C1180E000F279EC /* TestNSRange.swift */; };
EA66F6361BEED03E00136161 /* TargetConditionals.h in Headers */ = {isa = PBXBuildFile; fileRef = EA66F6351BEED03E00136161 /* TargetConditionals.h */; settings = {ATTRIBUTES = (Public, ); }; };
EA66F6441BF1619600136161 /* main.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA66F6381BF1619600136161 /* main.swift */; };
Expand Down Expand Up @@ -525,6 +526,7 @@
84BA558D1C16F90900F48C54 /* TestNSTimeZone.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TestNSTimeZone.swift; sourceTree = "<group>"; };
C93559281C12C49F009FD6A9 /* TestNSAffineTransform.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TestNSAffineTransform.swift; sourceTree = "<group>"; };
DCDBB8321C1768AC00313299 /* TestNSData.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TestNSData.swift; sourceTree = "<group>"; };
83712C8D1C1684900049AD49 /* TestNSURLRequest.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TestNSURLRequest.swift; sourceTree = "<group>"; };
E876A73D1C1180E000F279EC /* TestNSRange.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TestNSRange.swift; sourceTree = "<group>"; };
EA313DFC1BE7F2E90060A403 /* CFURLComponents_Internal.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CFURLComponents_Internal.h; sourceTree = "<group>"; };
EA313DFD1BE7F2E90060A403 /* CFURLComponents_URIParser.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = CFURLComponents_URIParser.c; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1031,6 +1033,7 @@
DCDBB8321C1768AC00313299 /* TestNSData.swift */,
84BA558D1C16F90900F48C54 /* TestNSTimeZone.swift */,
844DC3321C17584F005611F9 /* TestNSScanner.swift */,
83712C8D1C1684900049AD49 /* TestNSURLRequest.swift */,
);
name = Tests;
sourceTree = "<group>";
Expand Down Expand Up @@ -1723,6 +1726,7 @@
52829AD71C160D64003BC4EF /* TestNSCalendar.swift in Sources */,
C93559291C12C49F009FD6A9 /* TestNSAffineTransform.swift in Sources */,
DCDBB8331C1768AC00313299 /* TestNSData.swift in Sources */,
83712C8E1C1684900049AD49 /* TestNSURLRequest.swift in Sources */,
EA66F64E1BF1619600136161 /* TestNSIndexSet.swift in Sources */,
22B9C1E11C165D7A00DECFF9 /* TestNSDate.swift in Sources */,
EA66F6541BF1619600136161 /* TestNSSet.swift in Sources */,
Expand Down
21 changes: 15 additions & 6 deletions Foundation/NSURLRequest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,10 @@ public enum NSURLRequestNetworkServiceType : UInt {
*/
public class NSURLRequest : NSObject, NSSecureCoding, NSCopying, NSMutableCopying {

private var _URL : NSURL?
private var _mainDocumentURL: NSURL?
private var _httpHeaderFields: [String: String]?

public func copyWithZone(zone: NSZone) -> AnyObject {
NSUnimplemented()
}
Expand All @@ -180,6 +184,8 @@ public class NSURLRequest : NSObject, NSSecureCoding, NSCopying, NSMutableCopyin
NSUnimplemented()
}

private override init() {}

/*!
@method requestWithURL:
@abstract Allocates and initializes an NSURLRequest with the given
Expand Down Expand Up @@ -219,14 +225,17 @@ public class NSURLRequest : NSObject, NSSecureCoding, NSCopying, NSMutableCopyin
@param URL The URL for the request.
@result An initialized NSURLRequest.
*/
public convenience init(URL: NSURL) { NSUnimplemented() }
public convenience init(URL: NSURL) {
self.init()
_URL = URL
}

/*!
@method URL
@abstract Returns the URL of the receiver.
@result The URL of the receiver.
*/
/*@NSCopying */public var URL: NSURL? { NSUnimplemented() }
/*@NSCopying */public var URL: NSURL? { return _URL }

/*!
@method mainDocumentURL
Expand All @@ -236,14 +245,14 @@ public class NSURLRequest : NSObject, NSSecureCoding, NSCopying, NSMutableCopyin
See setMainDocumentURL:
@result The main document URL.
*/
/*@NSCopying*/ public var mainDocumentURL: NSURL? { NSUnimplemented() }
/*@NSCopying*/ public var mainDocumentURL: NSURL? { return _mainDocumentURL }

/*!
@method HTTPMethod
@abstract Returns the HTTP request method of the receiver.
@result the HTTP request method of the receiver.
*/
public var HTTPMethod: String? { get { NSUnimplemented() }}
public var HTTPMethod: String? { get { return "GET" }}

/*!
@method allHTTPHeaderFields
Expand All @@ -252,7 +261,7 @@ public class NSURLRequest : NSObject, NSSecureCoding, NSCopying, NSMutableCopyin
@result a dictionary containing all the HTTP header fields of the
receiver.
*/
public var allHTTPHeaderFields: [String : String]? { NSUnimplemented() }
public var allHTTPHeaderFields: [String : String]? { return _httpHeaderFields }

/*!
@method valueForHTTPHeaderField:
Expand All @@ -264,7 +273,7 @@ public class NSURLRequest : NSObject, NSSecureCoding, NSCopying, NSMutableCopyin
@result the value associated with the given header field, or nil if
there is no value associated with the given header field.
*/
public func valueForHTTPHeaderField(field: String) -> String? { NSUnimplemented() }
public func valueForHTTPHeaderField(field: String) -> String? { return _httpHeaderFields?[field.lowercaseString] }

}

Expand Down
37 changes: 37 additions & 0 deletions TestFoundation/TestNSURLRequest.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2015 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See http://swift.org/LICENSE.txt for license information
// See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//


#if DEPLOYMENT_RUNTIME_OBJC || os(Linux)
import Foundation
import XCTest
#else
import SwiftFoundation
import SwiftXCTest
#endif

class TestNSURLRequest : XCTestCase {

var allTests : [(String, () -> ())] {
return [
("test_construction", test_construction),
]
}

func test_construction() {
let URL = NSURL(string: "http://swift.org")!
let request = NSURLRequest(URL: URL)
// Match OS X Foundation responses
XCTAssertNotNil(request)
XCTAssertEqual(request.URL, URL)
XCTAssertEqual(request.HTTPMethod, "GET")
XCTAssertNil(request.allHTTPHeaderFields)
XCTAssertNil(request.mainDocumentURL)
}
}
1 change: 1 addition & 0 deletions TestFoundation/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,5 @@ XCTMain([
TestNSData(),
TestNSTimeZone(),
TestNSScanner(),
TestNSURLRequest()
])