526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
...
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
...
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
...
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
|
end
-- check for a content-type header, and see if it's a multipart/
-- form-data encoded POST request so we can handle file uploads
co.uploads.sz = 0 co.uploads.run = 0
if co.method == [lib.http.method.post] then
var ctt = lib.http.findheader(msg, 'Content-Type')
if ctt ~= nil then
lib.dbg('found content type', {ctt.ptr,ctt.ct})
if lib.str.ncmp(ctt.ptr,'multipart/form-data;',20) == 0 then
var p = lib.str.ffw(ctt.ptr + 20,ctt.ct-20)
if lib.str.ncmp(p,'boundary=',9) ~= 0 then
co:complain(400,'bad request','unrecognized content-type')
goto fail
end
var boundary = pstring {ptr=p+9,ct=ctt.ct - ((p - ctt.ptr) + 9)}
lib.dbg('got boundary ',{boundary.ptr,boundary.ct})
co.method = lib.http.method.post_file
co.uploads:init(8)
var bsr = (lib.str.acc{}):compose('\r\n--',boundary,'\r\n'):finalize()
var upmap = lib.str.splitmap(co.body,bsr,8)
-- first entry may not be preceded by header-break
................................................................................
lsent.ct = halt.ptr - lsent.ptr
end
lsr:free() end
for i=0,upmap.ct do
var hdrbrk = lib.str.find(upmap(i), lib.str.plit'\r\n\r\n')
if hdrbrk:ref() then
lib.dbg('got new entry')
var hdrtxt = pstring {upmap(i).ptr,upmap(i).ct - hdrbrk.ct}
var hdrs = lib.str.splitmap(hdrtxt, '\r\n',6)
var ctt = pstring.null()
var ctd = pstring.null()
for j=0, hdrs.ct do
var brk = lib.str.find(hdrs(j),lib.str.plit':')
if brk:ref() then
................................................................................
ctd = val
end
end
end
if ctd:ref() then
var ctdvals = lib.str.splitmap(ctd, ';', 4) defer ctdvals:free()
if ctdvals(0):cmp(lib.str.plit'form-data') and ctdvals.ct > 1 then
lib.dbg('found form data')
var fld = pstring.null()
var file = pstring.null()
for j=1, ctdvals.ct do var v = ctdvals(j):ffw()
var x = lib.str.find(v,lib.str.plit'=')
if x:ref() then
var key = pstring{v.ptr, v.ct - x.ct}
var val = pstring{x.ptr + 1, x.ct - 1}
................................................................................
end
end
end
return 0
end
--9twh8y94i5c1qqr7hxu20fyd
terra cfgcache.methods.load :: {&cfgcache} -> {}
terra cfgcache:init(o: &srv)
self.overlord = o
self:load()
end
terra srv:setup(befile: rawstring)
|
|
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
...
559
560
561
562
563
564
565
566
567
568
569
570
571
572
...
578
579
580
581
582
583
584
585
586
587
588
589
590
591
...
772
773
774
775
776
777
778
779
780
781
782
783
784
785
|
end
-- check for a content-type header, and see if it's a multipart/
-- form-data encoded POST request so we can handle file uploads
co.uploads.sz = 0 co.uploads.run = 0
if co.method == [lib.http.method.post] then
var ctt = lib.http.findheader(msg, 'Content-Type')
if ctt ~= nil then
if lib.str.ncmp(ctt.ptr,'multipart/form-data;',20) == 0 then
var p = lib.str.ffw(ctt.ptr + 20,ctt.ct-20)
if lib.str.ncmp(p,'boundary=',9) ~= 0 then
co:complain(400,'bad request','unrecognized content-type')
goto fail
end
var boundary = pstring {ptr=p+9,ct=ctt.ct - ((p - ctt.ptr) + 9)}
co.method = lib.http.method.post_file
co.uploads:init(8)
var bsr = (lib.str.acc{}):compose('\r\n--',boundary,'\r\n'):finalize()
var upmap = lib.str.splitmap(co.body,bsr,8)
-- first entry may not be preceded by header-break
................................................................................
lsent.ct = halt.ptr - lsent.ptr
end
lsr:free() end
for i=0,upmap.ct do
var hdrbrk = lib.str.find(upmap(i), lib.str.plit'\r\n\r\n')
if hdrbrk:ref() then
var hdrtxt = pstring {upmap(i).ptr,upmap(i).ct - hdrbrk.ct}
var hdrs = lib.str.splitmap(hdrtxt, '\r\n',6)
var ctt = pstring.null()
var ctd = pstring.null()
for j=0, hdrs.ct do
var brk = lib.str.find(hdrs(j),lib.str.plit':')
if brk:ref() then
................................................................................
ctd = val
end
end
end
if ctd:ref() then
var ctdvals = lib.str.splitmap(ctd, ';', 4) defer ctdvals:free()
if ctdvals(0):cmp(lib.str.plit'form-data') and ctdvals.ct > 1 then
var fld = pstring.null()
var file = pstring.null()
for j=1, ctdvals.ct do var v = ctdvals(j):ffw()
var x = lib.str.find(v,lib.str.plit'=')
if x:ref() then
var key = pstring{v.ptr, v.ct - x.ct}
var val = pstring{x.ptr + 1, x.ct - 1}
................................................................................
end
end
end
return 0
end
terra cfgcache.methods.load :: {&cfgcache} -> {}
terra cfgcache:init(o: &srv)
self.overlord = o
self:load()
end
terra srv:setup(befile: rawstring)
|