Skip to content
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

Move HTTPRequest.url to the main library #79

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//
// This source file is part of the Swift open source project
//
// Copyright (c) 2023 Apple Inc. and the Swift project authors
// Copyright (c) 2023-2024 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0
//
// See LICENSE.txt for license information
Expand All @@ -12,10 +12,14 @@
//
//===----------------------------------------------------------------------===//

#if canImport(FoundationEssentials)
import FoundationEssentials
#else
import Foundation
import HTTPTypes
#endif

#if canImport(CoreFoundation)
import Foundation
import CoreFoundation
#endif // canImport(CoreFoundation)

Expand Down
15 changes: 15 additions & 0 deletions Sources/HTTPTypesFoundation/HTTPTypesFoundation.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
//===----------------------------------------------------------------------===//
//
// This source file is part of the Swift open source project
//
// Copyright (c) 2024 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0
//
// See LICENSE.txt for license information
// See CONTRIBUTORS.txt for the list of Swift project authors
//
// SPDX-License-Identifier: Apache-2.0
//
//===----------------------------------------------------------------------===//

@_exported import HTTPTypes
65 changes: 1 addition & 64 deletions Tests/HTTPTypesFoundationTests/HTTPTypesFoundationTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//
// This source file is part of the Swift open source project
//
// Copyright (c) 2023 Apple Inc. and the Swift project authors
// Copyright (c) 2023-2024 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0
//
// See LICENSE.txt for license information
Expand All @@ -12,7 +12,6 @@
//
//===----------------------------------------------------------------------===//

import HTTPTypes
import HTTPTypesFoundation
import XCTest

Expand All @@ -21,68 +20,6 @@ import FoundationNetworking
#endif

final class HTTPTypesFoundationTests: XCTestCase {
func testRequestURLParsing() {
let request1 = HTTPRequest(url: URL(string: "h://a")!)
XCTAssertEqual(request1.scheme, "h")
XCTAssertEqual(request1.authority, "a")
XCTAssertEqual(request1.path, "/")
XCTAssertEqual(request1.url?.absoluteString, "h://a/")

let request2 = HTTPRequest(url: URL(string: "h://a:4?")!)
XCTAssertEqual(request2.scheme, "h")
XCTAssertEqual(request2.authority, "a:4")
XCTAssertEqual(request2.path, "/?")
XCTAssertEqual(request2.url?.absoluteString, "h://a:4/?")

let request3 = HTTPRequest(url: URL(string: "h://a/")!)
XCTAssertEqual(request3.scheme, "h")
XCTAssertEqual(request3.authority, "a")
XCTAssertEqual(request3.path, "/")
XCTAssertEqual(request3.url?.absoluteString, "h://a/")

let request4 = HTTPRequest(url: URL(string: "h://a/p?q#1")!)
XCTAssertEqual(request4.scheme, "h")
XCTAssertEqual(request4.authority, "a")
XCTAssertEqual(request4.path, "/p?q")
XCTAssertEqual(request4.url?.absoluteString, "h://a/p?q")

let request5 = HTTPRequest(url: URL(string: "data:,Hello%2C%20World%21")!)
XCTAssertEqual(request5.scheme, "data")
XCTAssertNil(request5.authority)
#if canImport(CoreFoundation)
XCTAssertEqual(request5.path, "/")
#else // canImport(CoreFoundation)
XCTAssertEqual(request5.path, ",Hello%2C%20World%21")
#endif // canImport(CoreFoundation)
XCTAssertNil(request5.url)
}

func testRequestURLAuthorityParsing() {
let request1 = HTTPRequest(url: URL(string: "https://[::1]")!)
XCTAssertEqual(request1.scheme, "https")
XCTAssertEqual(request1.authority, "[::1]")
XCTAssertEqual(request1.path, "/")
XCTAssertEqual(request1.url?.absoluteString, "https://[::1]/")

let request2 = HTTPRequest(url: URL(string: "https://[::1]:443")!)
XCTAssertEqual(request2.scheme, "https")
XCTAssertEqual(request2.authority, "[::1]:443")
XCTAssertEqual(request2.path, "/")
XCTAssertEqual(request2.url?.absoluteString, "https://[::1]:443/")

let request3 = HTTPRequest(url: URL(string: "https://127.0.0.1")!)
XCTAssertEqual(request3.scheme, "https")
XCTAssertEqual(request3.authority, "127.0.0.1")
XCTAssertEqual(request3.path, "/")
XCTAssertEqual(request3.url?.absoluteString, "https://127.0.0.1/")

let request4 = HTTPRequest(url: URL(string: "https://127.0.0.1:443")!)
XCTAssertEqual(request4.scheme, "https")
XCTAssertEqual(request4.authority, "127.0.0.1:443")
XCTAssertEqual(request4.path, "/")
XCTAssertEqual(request4.url?.absoluteString, "https://127.0.0.1:443/")
}

func testRequestToFoundation() throws {
let request = HTTPRequest(
method: .get,
Expand Down
86 changes: 86 additions & 0 deletions Tests/HTTPTypesTests/HTTPTypesURLTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
//===----------------------------------------------------------------------===//
//
// This source file is part of the Swift open source project
//
// Copyright (c) 2024 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0
//
// See LICENSE.txt for license information
// See CONTRIBUTORS.txt for the list of Swift project authors
//
// SPDX-License-Identifier: Apache-2.0
//
//===----------------------------------------------------------------------===//

import HTTPTypes
import XCTest

#if canImport(FoundationEssentials)
import FoundationEssentials
#else
import Foundation
#endif

final class HTTPTypesURLTests: XCTestCase {
func testRequestURLParsing() {
let request1 = HTTPRequest(url: URL(string: "h://a")!)
XCTAssertEqual(request1.scheme, "h")
XCTAssertEqual(request1.authority, "a")
XCTAssertEqual(request1.path, "/")
XCTAssertEqual(request1.url?.absoluteString, "h://a/")

let request2 = HTTPRequest(url: URL(string: "h://a:4?")!)
XCTAssertEqual(request2.scheme, "h")
XCTAssertEqual(request2.authority, "a:4")
XCTAssertEqual(request2.path, "/?")
XCTAssertEqual(request2.url?.absoluteString, "h://a:4/?")

let request3 = HTTPRequest(url: URL(string: "h://a/")!)
XCTAssertEqual(request3.scheme, "h")
XCTAssertEqual(request3.authority, "a")
XCTAssertEqual(request3.path, "/")
XCTAssertEqual(request3.url?.absoluteString, "h://a/")

let request4 = HTTPRequest(url: URL(string: "h://a/p?q#1")!)
XCTAssertEqual(request4.scheme, "h")
XCTAssertEqual(request4.authority, "a")
XCTAssertEqual(request4.path, "/p?q")
XCTAssertEqual(request4.url?.absoluteString, "h://a/p?q")

let request5 = HTTPRequest(url: URL(string: "data:,Hello%2C%20World%21")!)
XCTAssertEqual(request5.scheme, "data")
XCTAssertNil(request5.authority)
#if canImport(CoreFoundation)
XCTAssertEqual(request5.path, "/")
#else // canImport(CoreFoundation)
XCTAssertEqual(request5.path, ",Hello%2C%20World%21")
#endif // canImport(CoreFoundation)
XCTAssertNil(request5.url)
}

func testRequestURLAuthorityParsing() {
let request1 = HTTPRequest(url: URL(string: "https://[::1]")!)
XCTAssertEqual(request1.scheme, "https")
XCTAssertEqual(request1.authority, "[::1]")
XCTAssertEqual(request1.path, "/")
XCTAssertEqual(request1.url?.absoluteString, "https://[::1]/")

let request2 = HTTPRequest(url: URL(string: "https://[::1]:443")!)
XCTAssertEqual(request2.scheme, "https")
XCTAssertEqual(request2.authority, "[::1]:443")
XCTAssertEqual(request2.path, "/")
XCTAssertEqual(request2.url?.absoluteString, "https://[::1]:443/")

let request3 = HTTPRequest(url: URL(string: "https://127.0.0.1")!)
XCTAssertEqual(request3.scheme, "https")
XCTAssertEqual(request3.authority, "127.0.0.1")
XCTAssertEqual(request3.path, "/")
XCTAssertEqual(request3.url?.absoluteString, "https://127.0.0.1/")

let request4 = HTTPRequest(url: URL(string: "https://127.0.0.1:443")!)
XCTAssertEqual(request4.scheme, "https")
XCTAssertEqual(request4.authority, "127.0.0.1:443")
XCTAssertEqual(request4.path, "/")
XCTAssertEqual(request4.url?.absoluteString, "https://127.0.0.1:443/")
}
}
Loading