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