https://github.com/asmod4n/mruby-phr
mruby wrapper for https://github.com/h2o/picohttpparser
https://github.com/asmod4n/mruby-phr
http-parser mruby picohttpparser
Last synced: 8 months ago
JSON representation
mruby wrapper for https://github.com/h2o/picohttpparser
- Host: GitHub
- URL: https://github.com/asmod4n/mruby-phr
- Owner: Asmod4n
- License: apache-2.0
- Created: 2015-01-13T05:54:17.000Z (almost 11 years ago)
- Default Branch: master
- Last Pushed: 2025-01-16T21:27:08.000Z (12 months ago)
- Last Synced: 2025-04-07T03:34:34.936Z (9 months ago)
- Topics: http-parser, mruby, picohttpparser
- Language: C
- Homepage:
- Size: 42 KB
- Stars: 8
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# mruby-phr
A small http parser for mruby based on https://github.com/h2o/picohttpparser
Examples
=======
```ruby
buffer = "HTTP/1.1 200 OK\r\nContent-Length: 5\r\nConnection: close\r\n\r\nhallo"
phr = Phr.new
offset = phr.parse_response buffer
puts phr.minor_version
puts phr.status
puts phr.msg
puts phr.headers
body = buffer[offset..-1]
puts body
phr.reset
buffer = "POST / HTTP/1.1\r\nHost: www.google.com\r\nContent-Length: 5\r\nConnection: close\r\n\r\nhallo"
offset = phr.parse_request buffer
puts phr.method
puts phr.path
puts phr.minor_version
puts phr.headers
body = buffer[offset..-1]
puts body
phr.reset
buffer = "b\r\nhello world\r\n0\r\n"
phr.decode_chunked(buffer)
puts buffer
phr.reset
```
Return values
-------------
Phr has three response values
:parser_error when a request was malformed
:incomplete when the supplied buffer doesnt hold a complete request
Or a Integer value describing where the body starts.