File: http.lua

package info (click to toggle)
lua-uri 0.1%2B20130926%2Bgit14fa255d-1
  • links: PTS, VCS
  • area: main
  • in suites: buster, jessie, jessie-kfreebsd, stretch
  • size: 408 kB
  • ctags: 332
  • sloc: makefile: 53
file content (67 lines) | stat: -rw-r--r-- 1,944 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
require "uri-test"
local URI = require "uri"

module("test.http", lunit.testcase, package.seeall)

function test_http ()
    local uri = assert(URI:new("HTtp://FOo/Blah?Search#Id"))
    is("uri.http", uri._NAME)
    is("http://foo/Blah?Search#Id", uri:uri())
    is("http://foo/Blah?Search#Id", tostring(uri))
    is("http", uri:scheme())
    is("foo", uri:host())
    is(80, uri:port())
    is("/Blah", uri:path())
    is(nil, uri:userinfo())
    is("Search", uri:query())
    is("Id", uri:fragment())
end

function test_https ()
    local uri = assert(URI:new("HTtpS://FOo/Blah?Search#Id"))
    is("uri.https", uri._NAME)
    is("https://foo/Blah?Search#Id", uri:uri())
    is("https://foo/Blah?Search#Id", tostring(uri))
    is("https", uri:scheme())
    is("foo", uri:host())
    is(443, uri:port())
    is("/Blah", uri:path())
    is(nil, uri:userinfo())
    is("Search", uri:query())
    is("Id", uri:fragment())
end

function test_http_port ()
    local uri = assert(URI:new("http://example.com:8080/foo"))
    is(8080, uri:port())
    local old = uri:port(1234)
    is(8080, old)
    is(1234, uri:port())
    is("http://example.com:1234/foo", tostring(uri))
    old = uri:port(80)
    is(1234, old)
    is(80, uri:port())
    is("http://example.com/foo", tostring(uri))
end

function test_normalize_port ()
    local uri = assert(URI:new("http://foo:80/"))
    is("http://foo/", tostring(uri))
    is(80, uri:port())
    uri = assert(URI:new("http://foo:443/"))
    is("http://foo:443/", tostring(uri))
    is(443, uri:port())
    uri = assert(URI:new("https://foo:443/"))
    is("https://foo/", tostring(uri))
    is(443, uri:port())
    uri = assert(URI:new("https://foo:80/"))
    is("https://foo:80/", tostring(uri))
    is(80, uri:port())
end

function test_set_userinfo ()
    local uri = assert(URI:new("http://host/path"))
    assert_error("can't set userinfo", function () uri:userinfo("x") end)
end

-- vi:ts=4 sw=4 expandtab