Skip to content

Instantly share code, notes, and snippets.

@wycats
Created January 13, 2014 06:34
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wycats/8395627 to your computer and use it in GitHub Desktop.
Save wycats/8395627 to your computer and use it in GitHub Desktop.

Request

struct Request {
  remote_addr: SocketAddr,
  method: Method,
  uri: Uri,
  version: (uint, uint),
  cert: Option<X509Certificate>,
  headers: HeaderCollection
}

HeaderCollection

struct HeaderCollection {
  // RFC 2616, Section 4.5: General Header Fields
  cache_control: Option<CacheControl>,
  connection: Option<~[Connection]>,
  date: Option<Tm>,
  pragma: Option<Pragma>,
  trailer: Option<~str>,
  transfer_encoding: Option<~[TransferCoding]>,
  upgrade: Option<Upgrade>,
  via: Option<Via>,
  warning: Option<Warning>,

  // RFC 2616, Section 5.3: Request Header Fields
  accept: Option<Accept>,
  accept_charset: Option<~[AcceptCharset]>,
  accept_encoding: Option<~[AcceptEncoding]>,
  accept_language: Option<~[AcceptLanguage]>,
  authorization: Option<Credentials>,
  expect: Option<~[Expectation]>,
  from: Option<~str>,
  host: Option<Host>,
  if_match: Option<~[IfMatch]>,
  if_modified_since: Option<Tm>,
  if_none_match: Option<IfMatch>,
  if_range: Option<IfRange>,
  if_unmodified_since: Option<Tm>,
  max_forwards: Option<uint>,
  proxy_authorization: Option<Credentials>,
  range: Option<Range>,
  referer: Option<Url>,
  te: Option<~[Te]>,
  user_agent: Option<UserAgent>,

  // RFC 2616, Section 7.1: Entity Header Fields
  allow: Option<~[Method]>,
  content_encoding: Option<~str>,
  content_language: Option<~str>,
  content_length: Option<uint>,
  content_location: Option<~str>,
  content_md5: Option<~str>,
  content_range: Option<~str>,
  content_type: Option<MediaType>,
  expires: Option<Tm>,
  last_modified Option<Tm>
}

Connection

enum Connection {
  Token(~str),
  Close
}

Cache-Control

type CacheControl = ~[CacheDirective]

enum CacheDirective {
  Request(RequestDirective),
  Response(ResponseDirective)
}

enum RequestDirective {
  NoCache,
  NoStore,
  MaxAge(uint),
  MaxStale(Option<uint>),
  MinFresh(uint),
  NoTransform,
  OnlyIfCached,
  Extension(CacheExtension)
}

enum ResponseDirective {
  Public,
  Private(Option<~[~str]>),
  NoCache(Option<~[~str]>),
  NoStore,
  NoTransform,
  MustRevalidate,
  ProxyRevalidate,
  MaxAge(uint),
  SMaxAge(uint),
  Extension(Map<~str, Option<~str>>)
}

Pragma

enum Pragma {
  NoCache,
  Extension(Map<~str, Option<~str>>)
}

Transfer-Encoding

enum TransferCoding {
  Chunked,
  TransferExtension(~str, ~[(~str, ~str)])
}

Product

struct Product {
  product: ~str,
  version: ~str
}

Upgrade

type Upgrade = ~[Product];

Via

type Via = ~[ViaEntry]

struct ViaEntry {
  protocol_name: Option<~str>,
  protocol_version: ~str,
  received_by: ReceivedBy,
  comment: ~str
}

enum ReceivedBy {
  Location(IpAddr, uint),
  Pseudonym(~str)
}

Warning

type Warning = ~[WarningValue];

struct WarningValue {
  warn_code: uint,
  warn_agent: WarnAgent,
  warn_text: ~str,
  warn_date: Tm
}

enum WarnAgent {
  Location(IpAddr, uint),
  Pseudonym(~str)
}

Accept

type Accept = ~[MediaRange];

struct MediaRange {
  media_type: MediaType,
  parameters: Option<Map<~str, ~str>>,
  accept_params: AcceptParams
}

struct AcceptParams {
  quality: Option<f32>,
  extensions: Option<Map<~str, Option<~str>>
}

enum MediaType {
  Any,
  AnySubtype(~str),
  Specific(~str, ~str)
}

Accept-Charset

struct AcceptCharset {
  charset: Charset,
  quality: Option<f32>
}

enum Charset {
  Any,
  Charset(~str)
}

Accept-Encoding

struct AcceptEncoding {
  codings: Codings,
  quality: Option<f32>
}

enum Codings {
  Any,
  Coding(~str)
}

Accept-Language

struct AcceptLanguage {
  range: LanguageRange,
  quality: Option<f32>
}

enum LanguageRange {
  Any,
  Range(~[~str])
}

Credentials

struct Credentials {
  auth_scheme: ~str,
  auth_params: Option<Map<~str, Option<~str>>
}

Expect

enum Expectation {
  Continue,
  Extension(Map<~str, ~[ExpectationValue]>)
}

struct ExpectationValue {
  value: ~str,
  params: Map<~str, ~str>
}

If-Match

enum IfMatch {
  Any,
  ETag(~[EntityTag])
}

EntityTag

struct EntityTag {
  weak: bool,
  tag: ~str
}

If-Range

enum IfRange {
  ETag(EntityTag),
  Date(Tm)
}

Range

enum Range {
  ByteRange(uint, Option<uint>),
  SuffixByteRange(uint)  
}

TE

enum Te {
  Trailers,
  Codings(TransferExtension, Option<AcceptParams>)
}

User-Agent

enum UserAgent {
  Product(Product),
  Comment(~str)
}

Method

enum Method {
  Options,
  Get,
  Head,
  Post,
  Put,
  Delete,
  Trace,
  Connect,
  Patch, // RFC 5789
  ExtensionMethod(~str),
}

MediaType

struct MediaType {
  type_: ~str,
  subtype: ~str,
  parameters: ~[(~str, ~str)]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment