Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/yockow/swiftnetworkgear
`SwiftNetworkGear` will provide various functions about network.
https://github.com/yockow/swiftnetworkgear
Last synced: 24 days ago
JSON representation
`SwiftNetworkGear` will provide various functions about network.
- Host: GitHub
- URL: https://github.com/yockow/swiftnetworkgear
- Owner: YOCKOW
- License: mit
- Created: 2018-07-02T08:12:11.000Z (over 6 years ago)
- Default Branch: main
- Last Pushed: 2024-05-07T03:56:09.000Z (6 months ago)
- Last Synced: 2024-05-08T04:32:14.287Z (6 months ago)
- Language: Swift
- Homepage:
- Size: 385 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# What is `SwiftNetworkGear`?
`SwiftNetworkGear` will provide various functions about network.
It was originally written as a part of [SwiftCGIResponder](https://github.com/YOCKOW/SwiftCGIResponder).# Requirements
- Swift 5, 6
- macOS(>=10.15) or Linux## Dependencies
![Dependencies](./dependencies.svg)
# Usage
```Swift
import NetworkGear
import Foundation// DNS Lookup
Domain("GitHub.com")!.ipAddresses
//// -> [192.30.255.112, 192.30.255.113]// DNS Reverse Lookup
IPAddress(string:"192.30.255.112")!.domain!
//// -> lb-192-30-255-112-sea.github.com// Punycode
Domain("www.日本.jp")!.description
//// -> www.xn--wgv71a.jp// Extended URL
URL(internationalString:"https://USER:PASSWORD@にっぽん。JP:8080/☕︎.cgi?杯=2#MyCoffee")!
//// -> https://USER:[email protected]:8080/%E2%98%95.cgi?%E6%9D%AF=2#MyCoffee// Public Suffix
Domain("YOCKOW.jp")!.isPublicSuffix
//// -> false
Domain("YOCKOW.JP")!.publicSuffix!.description
//// -> jp
```## `SimpleHTTPConnection`
There is a type named `SimpleHTTPConnection` that doesn't depend on `URLSession` but directly use
[libcurl](https://curl.se/libcurl/) as its backend.```Swift
import NetworkGearlet url = URL(string: "https://httpbin.org/post")!
let connection = SimpleHTTPConnection(
url: url,
method: .post,
requestHeader: [
.contentLength(7),
.contentType(.wwwFormURLEncoded),
],
requestBody: .init(data: Data("foo=bar".utf8)),
redirectStrategy: .noFollow
)
let response = try await connection.response()
let content = response.content
```# License
MIT License.
See "LICENSE.txt" for more information.