Mercurial Hosting > luan
comparison http/src/luan/modules/http/Http.luan @ 499:fa4af530697f
add http/dump
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Mon, 18 May 2015 14:24:50 -0600 |
parents | ee55be414a34 |
children | ab9c2afefb47 |
comparison
equal
deleted
inserted
replaced
498:ee55be414a34 | 499:fa4af530697f |
---|---|
6 local Io = require "luan:Io" | 6 local Io = require "luan:Io" |
7 local Html = require "luan:Html" | 7 local Html = require "luan:Html" |
8 local url_encode = Html.url_encode | 8 local url_encode = Html.url_encode |
9 local HttpServicer = require "java:luan.modules.http.HttpServicer" | 9 local HttpServicer = require "java:luan.modules.http.HttpServicer" |
10 local IoLuan = require "java:luan.modules.IoLuan" | 10 local IoLuan = require "java:luan.modules.IoLuan" |
11 | |
12 | |
13 to_header_name = HttpServicer.toHeaderName | |
11 | 14 |
12 | 15 |
13 local singular_metatable = {} | 16 local singular_metatable = {} |
14 | 17 |
15 function singular_metatable.__index(table,key) | 18 function singular_metatable.__index(table,key) |
48 this.parameters = {} | 51 this.parameters = {} |
49 this.parameter = {__plural=this.parameters} | 52 this.parameter = {__plural=this.parameters} |
50 set_metatable(this.parameter,singular_metatable) | 53 set_metatable(this.parameter,singular_metatable) |
51 this.cookie = {} | 54 this.cookie = {} |
52 | 55 |
53 function this.url() | 56 function this.query_string() |
54 local string_uri = Io.uri "string:" | 57 local string_uri = Io.uri "string:" |
55 local out = string_uri.text_writer() | 58 local out = string_uri.text_writer() |
56 | 59 local and_char = "" |
57 out.write( this.scheme, "://", this.header.host, this.path ) | 60 for name, values in pairs(this.parameters) do |
58 if this.method ~= "POST" then | 61 for _, value in ipairs(values) do |
59 local and_char = "?" | 62 out.write( and_char, url_encode(name), "=", url_encode(value) ) |
60 for name, values in pairs(this.parameters) do | 63 and_char = "&" |
61 for _, value in ipairs(values) do | |
62 out.write( and_char, url_encode(name), "=", url_encode(value) ) | |
63 and_char = "&" | |
64 end | |
65 end | 64 end |
66 end | 65 end |
66 out.close() | |
67 local s = string_uri.read_text() | |
68 return s == "" and nil or s | |
69 end | |
67 | 70 |
68 out.close() | 71 function this.url() |
69 return string_uri.read_text() | 72 local url = this.scheme.."://"..this.header.host..this.path |
73 if this.method ~= "POST" then | |
74 local query = this.query_string() | |
75 if query ~= nil then | |
76 url = url.."?"..query | |
77 end | |
78 end | |
79 return url | |
70 end | 80 end |
71 | 81 |
72 return this | 82 return this |
73 end | 83 end |
74 | 84 |
98 end | 108 end |
99 return this | 109 return this |
100 end | 110 end |
101 | 111 |
102 -- request = new_request{} -- filled in by HttpServicer | 112 -- request = new_request{} -- filled in by HttpServicer |
113 -- response = new_response{} -- filled in by HttpServicer | |
103 | 114 |
104 | 115 |
105 | 116 |
106 function init_for_test() | 117 function init_for_test() |
107 | 118 |