Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/kostya/http_parser.cr
Crystal wrapper for Http Parser lib: https://github.com/joyent/http-parser
https://github.com/kostya/http_parser.cr
Last synced: 12 days ago
JSON representation
Crystal wrapper for Http Parser lib: https://github.com/joyent/http-parser
- Host: GitHub
- URL: https://github.com/kostya/http_parser.cr
- Owner: kostya
- License: mit
- Created: 2014-06-15T12:46:08.000Z (about 10 years ago)
- Default Branch: master
- Last Pushed: 2017-02-27T07:50:46.000Z (over 7 years ago)
- Last Synced: 2024-03-03T08:34:40.585Z (4 months ago)
- Language: C
- Homepage:
- Size: 114 KB
- Stars: 16
- Watchers: 3
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Lists
- awesome-crystal - http_parser.cr - Wrapper for [Http Parser lib](https://github.com/nodejs/http-parser) (HTTP)
- awesome-crystal - http_parser.cr - Wrapper for [Http Parser lib](https://github.com/nodejs/http-parser) (HTTP)
README
# HttpParser
Crystal wrapper for Http Parser lib: https://github.com/joyent/http-parser. And for Http multipart parser https://github.com/iafonov/multipart-parser-c
## Installation
Add this to your application's `shard.yml`:
```yaml
dependencies:
http_parser:
github: kostya/http_parser.cr
branch: master
```## Usage
```crystal
require "http_parser"puts HttpParser.version_string
str = "
GET / HTTP/1.1
Host: www.example.com
Connection: keep-alive
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_3) AppleWebKit/535.11 (KHTML, like Gecko) Chrome/17.0.963.78 S
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Encoding: gzip,deflate,sdch
Accept-Language: en-US,en;q=0.8
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3"
parser = HttpParser::Request.new
parser << strp parser.headers
p parser.method
p parser.http_version
p parser.request_url
```Multipart Example:
```crystal
str = "--AaB03x\r\n"+
"content-disposition: form-data; name=\"field1\"\r\n"+
"\r\n"+
"Joe Blow\r\nalmost tricked you!\r\n"+
"--AaB03x\r\n"+
"content-disposition: form-data; name=\"pics\"; filename=\"file1.txt\"\r\n"+
"Content-Type: text/plain\r\n"+
"\r\n"+
"... contents of file1.txt ...\r\r\n"+
"--AaB03x--\r\n"m = HttpParser::Multipart.new("AaB03x")
m << str
p m.parts
```