Types and helper functions for dealing with the HTTP in Julia
31 Stars
Updated Last
2 Years Ago
Started In
April 2013


Build Status

HttpCommon HttpCommon

Installation: julia> Pkg.add("HttpCommon")

This package provides types and helper functions for dealing with the HTTP protocol in Julia:

  • Types to represent Headers, Requests, Cookies, and Responses
  • A dictionary of STATUS_CODES that maps HTTP codes to descriptions
  • Utility functions escapeHTMLand parsequerystring

HTTP Types


Headers represents the header fields for an HTTP request, and is type alias for Dict{AbstractString,AbstractString}. There is a default constructor, headers, that produces a reasonable default set of headers:

Dict( "Server"           => "Julia/$VERSION",
      "Content-Type"     => "text/html; charset=utf-8",
      "Content-Language" => "en",
      "Date"             => Dates.format(now(Dates.UTC), Dates.RFC1123Format) )


A Request represents an HTTP request sent by a client to a server. It has five fields:

  • method: an HTTP methods string (e.g. "GET")
  • resource: the resource requested (e.g. "/hello/world")
  • headers: see Headers above
  • data: the data in the request as a vector of bytes
  • uri: additional details, normally not used


A Cookie represents an HTTP cookie. It has three fields: name and value are strings, and attrs is dictionary of pairs of strings.


A Response represents an HTTP response sent to a client by a server. It has six fields:

  • status: HTTP status code (see STATUS_CODES) [default: 200]
  • headers: Headers [default: HttpCommmon.headers()]
  • cookies: Dictionary of strings => Cookies
  • data: the request data as a vector of bytes [default: UInt8[]]
  • finished: true if the Reponse is valid, meaning that it can be converted to an actual HTTP response [default: false]
  • requests: the history of requests that generated the response. Can be greater than one if a redirect was involved.

Response has many constructors - use methods(Response) for full list.



STATUS_CODES is a dictionary (Int => AbstractString) that maps all the status codes defined in RFC's to their descriptions, e.g.

STATUS_CODES[200] # => "OK"
STATUS_CODES[404] # => "Not Found"
STATUS_CODES[418] # => "I'm a teapot"
STATUS_CODES[500] # => "Internal Server Error"

Utility functions


Returns a string with special HTML characters escaped: &, <, >, ", '


Convert a valid querystring to a Dict:

q = "foo=bar&"
# Dict{String,String} with 2 entries:
#   "baz" => "<a href=''>hello world!</a>"
#   "foo" => "bar"

::         ::
:: Made at ::
::         ::
Hacker School

Required Packages