Merge: Added contributing guidelines and link from readme
[nit.git] / lib / nitcorn / http_request.nit
index 47e6823..1833fca 100644 (file)
@@ -3,6 +3,7 @@
 # Copyright 2013 Frederic Sevillano
 # Copyright 2013 Jean-Philippe Caissy <jpcaissy@piji.ca>
 # Copyright 2014 Alexis Laferrière <alexis.laf@xymus.net>
+# Copyright 2014 Alexandre Terrasa <alexandre@moz-code.org>
 #
 # Licensed under the Apache License, Version 2.0 (the "License");
 # you may not use this file except in compliance with the License.
 # Provides the `HttpRequest` class and services to create it
 module http_request
 
-import standard
+import core
 
 # A request received over HTTP, is build by `HttpRequestParser`
 class HttpRequest
-       private init do end
+       private init is old_style_init do end
 
        # HTTP protocol version
        var http_version: String
@@ -46,6 +47,9 @@ class HttpRequest
        # The header of this request
        var header = new HashMap[String, String]
 
+       # The raw body of the request.
+       var body = ""
+
        # The content of the cookie of this request
        var cookie = new HashMap[String, String]
 
@@ -110,8 +114,7 @@ class HttpRequestParser
        # Words of the first line
        private var first_line = new Array[String]
 
-       init do end
-
+       # Parse the `first_line`, `header_fields` and `body` of `full_request`.
        fun parse_http_request(full_request: String): nullable HttpRequest
        do
                clear_data
@@ -137,13 +140,14 @@ class HttpRequestParser
 
                        var parse_url = parse_url
                        http_request.get_args = parse_url
-                       http_request.all_args.recover_with parse_url
+                       http_request.all_args.add_all parse_url
                else
                        http_request.uri = first_line[1]
                end
 
                # POST args
                if http_request.method == "POST" then
+                       http_request.body = body
                        var lines = body.split_with('&')
                        for line in lines do if not line.trim.is_empty then
                                var parts = line.split_once_on('=')