Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/soutaro/smhttpclient
HTTP/1.1 client, based on socket
https://github.com/soutaro/smhttpclient
Last synced: 22 days ago
JSON representation
HTTP/1.1 client, based on socket
- Host: GitHub
- URL: https://github.com/soutaro/smhttpclient
- Owner: soutaro
- License: mit
- Created: 2015-11-04T23:18:20.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2015-12-03T12:32:40.000Z (almost 9 years ago)
- Last Synced: 2024-10-11T17:46:12.802Z (25 days ago)
- Language: Swift
- Size: 42 KB
- Stars: 8
- Watchers: 3
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# SMHTTPClient
[![CI Status](http://img.shields.io/travis/soutaro/SMHTTPClient.svg?style=flat)](https://travis-ci.org/soutaro/SMHTTPClient)
[![Version](https://img.shields.io/cocoapods/v/SMHTTPClient.svg?style=flat)](http://cocoapods.org/pods/SMHTTPClient)
[![License](https://img.shields.io/cocoapods/l/SMHTTPClient.svg?style=flat)](http://cocoapods.org/pods/SMHTTPClient)
[![Platform](https://img.shields.io/cocoapods/p/SMHTTPClient.svg?style=flat)](http://cocoapods.org/pods/SMHTTPClient)SMHTTPClient is a HTTP/1.1 client based on socket API.
Since it does not depend on NSURLSession, application transport security does not prohibit sending plain-text requests with this library.## Usage
```swift
let resolver = NameResolver(hostname: "your-server.local", port: 80)
resolver.run()
let addr = resolver.results.first!let request = HttpRequest(address: addr, path: "/", method: .GET, header: [("Host": "your-server.local")])
request.run()switch request.status {
case .Completed(let code, let header, let data):
// Success
case .Error(let error):
// An error occured
case .Aborted:
// Aborted
default:
// ...
}
```It provides a blocking API.
When you want to cancel a running request, you should call `request.abort()` from another thread.```swift
let request = HttpRequest(...)
let queue = dispatch_queue_create("abort.queue", nil)// Timeout after 5 seconds
let delay = 5 * Double(NSEC_PER_SEC)
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, Int64(delay)), queue, {
request.abort();
})request.run()
// request.status will be .Aborted
```## Installation
SMHTTPClient is available through [CocoaPods](http://cocoapods.org). To install
it, simply add the following line to your Podfile:```ruby
pod "SMHTTPClient"
```## Author
Soutaro Matsumoto, [email protected]
## License
SMHTTPClient is available under the MIT license. See the LICENSE file for more info.