Erreur d'interprétation du fichier web.xml
[wslsock.git] / wslsock.lua
1 -- *********************************************************************
2 -- wslsock.lua
3 -- *********************************************************************
4
5 -- Détermination de la taille d'un fichier
6 function wsls_fsize (name)
7   fso = io.open(name, "r")
8   s = fso:seek("end")
9   io.close(fso)
10   return s
11 end
12
13 -- Détermination de l'extension d'un fichier
14 function wsls_fext (name)
15   return string.match(name, "(%.%a+)$")
16 end
17
18 -- Détermination du fichier
19 function wsls_fname (tail)
20   return string.match(tail, "/?([%a%d%.%-]+)$")
21 end
22
23 -- GET simple
24 function wsls_get (base, tail)
25   http = require("socket.http")
26   ltn12 = require("ltn12")
27   file = wsls_fname(tail)
28   out = io.open(file, "w")
29   r, c, h = http.request {
30     url = "http://" .. base .. tail,
31     sink = ltn12.sink.file(out)
32   }
33   if c == 200 then
34     print ("Le fichier " .. file .. "(" .. 
35       wsls_fsize(file) .. " octets) est transféré !")
36   end
37 end
38
39
40 -- PUT simple
41 function wsls_put (base, tail)
42   http = require("socket.http")
43   ltn12 = require("ltn12")
44   file = wsls_fname(tail)
45   r, c, h = http.request {
46     method = "PUT",
47     url = "http://" .. base .. tail,
48     source = ltn12.source.file(io.open(file)),
49     headers = {
50       ["content-length"] = wsls_fsize(file)
51     }
52   }
53   if c == 200 then
54     print ("Le fichier " .. file .. "(" ..
55       wsls_fsize(file) .. " octets) est transféré !")
56   end
57 end
58
59

Licence Creative Commons Les fichiers de Syracuse sont mis à disposition (sauf mention contraire) selon les termes de la
Licence Creative Commons Attribution - Pas d’Utilisation Commerciale - Partage dans les Mêmes Conditions 4.0 International.