HTTPParser is an HTTP (RFC 2616) parser for Swift 3.0.
- Asynchronous parsing
- Handles persistent streams (keep-alive)
- Decodes chunked encoding
- Defends against buffer overflow attacks
HTTPParser wraps the C library http_parser used by node.js.
The parser works asynchronously so you should keep feeding it data that until it returns a request/response.
let parser = RequestParser()
while true {
do {
let data = getDataFromSomewhere()
if let request = try parser.parse(data) {
// do something with request
}
} catch {
// something bad happened :(
break
}
}
Parser works the same way for requests and responses.
let parser = ResponseParser()
while true {
do {
let data = getDataFromSomewhere()
if let response = try parser.parse(data) {
// do something with response
}
} catch {
// something bad happened :(
break
}
}
- Add
HTTPParser
to yourPackage.swift
import PackageDescription
let package = Package(
dependencies: [
.Package(url: "https://github.com/Zewo/HTTPParser.git", majorVersion: 0, minor: 9),
]
)
If you need any help you can join our Slack and go to the #help channel. Or you can create a Github issue in our main repository. When stating your issue be sure to add enough details, specify what module is causing the problem and reproduction steps.
The entire Zewo code base is licensed under MIT. By contributing to Zewo you are contributing to an open and engaged community of brilliant Swift programmers. Join us on Slack to get to know us!
This project is released under the MIT license. See LICENSE for details.