Types and helper functions for dealing with the HTTP in Julia
Clone or download
Latest commit 8b94736 Aug 10, 2018
Failed to load latest commit information.
src Fix deprecations Aug 8, 2018
test Fix deprecations Aug 8, 2018
.travis.yml Drop 0.6 support Aug 10, 2018
LICENSE.txt So many contributors Sep 6, 2015
README.md Prepare for 0.7 (#47) Jan 20, 2018
REQUIRE Drop 0.6 support Aug 10, 2018



Build Status codecov.io

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&baz=%3Ca%20href%3D%27http%3A%2F%2Fwww.hackershool.com%27%3Ehello%20world%21%3C%2Fa%3E"
# Dict{String,String} with 2 entries:
#   "baz" => "<a href='http://www.hackershool.com'>hello world!</a>"
#   "foo" => "bar"

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