Skip to content

AbrJA/PicoHTTPParser.jl

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

27 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PicoHTTPParser.jl

Build Status

A minimal, high-performance Julia wrapper around the picohttpparser C library. This package provides extremely fast HTTP request/response/headers parsing and chunked transfer decoding through a clean Julia interface.

🚀 Features

  • Parse HTTP requests, responses, and headers efficiently
  • Thin, zero-copy bindings to the C library via ccall
  • Built on top of PicoHTTPParser_jll

📦 Installation

pkg> add PicoHTTPParser

🧩 Usage Examples

using PicoHTTPParser

Parse request

message = """GET /index.html HTTP/1.1\r
Host: example.com\r
User-Agent: TestClient/1.0\r
Accept: */*\r
\r
"""

result = parse_request(message)

@show result.method
@show result.path
@show result.minor_version
@show result.headers
@show String(result.body)

Output:

result.method = "GET"
result.path = "/index.html"
result.minor_version = 1
result.headers = Dict("Host" => "example.com", "Accept" => "*/*", "User-Agent" => "TestClient/1.0")
String(result.body) = ""

Parse response

message = """HTTP/1.1 200 OK\r
Content-Type: text/plain\r
Content-Length: 5\r
\r
Hello""" |> Vector{UInt8}

result = parse_response(message)

@show result.status_code
@show result.minor_version
@show result.headers
@show result.reason
@show String(result.body)

Output:

result.status_code = 200
result.minor_version = 1
result.headers = Dict("Content-Length" => "5", "Content-Type" => "text/plain")
result.reason = "OK"
String(result.body) = "Hello"

Parse headers

message = """Host: example.com\r
User-Agent: curl/7.68.0\r
\r
"""

result = parse_headers(message)

@show result

Output:

result = Dict("Host" => "example.com", "User-Agent" => "curl/7.68.0")

Decode chunked

message = "4\r\nWiki\r\n5\r\npedia\r\n0\r\n\r\n"
decoder = ChunkedDecoder()
result = decode_chunked!(decoder, message)

@show result.done
@show String(result.data)

Output:

result.done = true
String(result.data) = "Wikipedia"

⚙️ Contributing

Any contributions are welcome!

About

Julia wrapper of high performance picohttpparser C library

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 2

  •  
  •  

Languages