@@ -613,7 +613,151 @@ class HTTPWasmClient : public HTTPClient {
613613
614614 return res;
615615 }
616- unique_ptr<HTTPResponse> Delete (DeleteRequestInfo &info) override { return nullptr ; }
616+ unique_ptr<HTTPResponse> Delete (DeleteRequestInfo &info) override {
617+ unique_ptr<HTTPResponse> res;
618+
619+ string path = host_port + info.url ;
620+ path = info.url ;
621+
622+ if (!web::experimental_s3_tables_global_proxy.empty ()) {
623+ if (info.url .rfind (web::experimental_s3_tables_global_proxy, 0 ) != 0 ) {
624+ auto id_table = path.find (" --table-s3.s3." );
625+ auto id_aws = path.find (" .amazonaws.com/" );
626+ if (id_table != std::string::npos && id_aws != std::string::npos && id_table < id_aws) {
627+ path = web::experimental_s3_tables_global_proxy + path.substr (8 );
628+ }
629+ }
630+ }
631+ if (path.rfind (" https://" , 0 != 0 )) {
632+ path = " https://" + path;
633+ }
634+
635+ int n = 0 ;
636+ for (auto h : info.headers ) {
637+ n++;
638+ }
639+
640+ char **z = (char **)(void *)malloc (n * 4 * 2 );
641+
642+ int i = 0 ;
643+ for (auto h : info.headers ) {
644+ z[i] = (char *)malloc (h.first .size () * 4 + 1 );
645+ memset (z[i], 0 , h.first .size () * 4 + 1 );
646+ memcpy (z[i], h.first .c_str (), h.first .size ());
647+ i++;
648+ z[i] = (char *)malloc (h.second .size () * 4 + 1 );
649+ memset (z[i], 0 , h.second .size () * 4 + 1 );
650+ memcpy (z[i], h.second .c_str (), h.second .size ());
651+ i++;
652+ }
653+
654+ // clang-format off
655+ char *exe = NULL ;
656+ exe = (char *)EM_ASM_PTR (
657+ {
658+ var url = (UTF8ToString ($0 ));
659+ if (typeof XMLHttpRequest === " undefined" ) {
660+ return 0 ;
661+ }
662+ const xhr = new XMLHttpRequest ();
663+ if (false && url.startsWith (" http://" )) {
664+ url = " https://" + url.substr (7 );
665+ }
666+ xhr.open (UTF8ToString ($3 ), url, false );
667+ xhr.responseType = " arraybuffer" ;
668+
669+ var i = 0 ;
670+ var len = $1 ;
671+ while (i < len*2 ) {
672+ var ptr1 = HEAP32[($2 )/4 + i ];
673+ var ptr2 = HEAP32[($2 )/4 + i + 1 ];
674+
675+ try {
676+ var z = encodeURI (UTF8ToString (ptr1));
677+ if (z === " Host" ) z = " X-Host-Override" ;
678+ if (z === " User-Agent" ) z = " X-user-agent" ;
679+ if (z === " Authorization" ) {
680+ xhr.setRequestHeader (z, UTF8ToString (ptr2));
681+ } else {
682+
683+ xhr.setRequestHeader (z, encodeURI (UTF8ToString (ptr2)));
684+ }
685+ } catch (error) {
686+ console.warn (" Error while performing XMLHttpRequest.setRequestHeader()" , error);
687+ }
688+ i += 2 ;
689+ }
690+
691+ try {
692+ xhr.send (null);
693+ } catch {
694+ return 0 ;
695+ }
696+ if (xhr.status >= 400 ) return 0 ;
697+ var uInt8Array = xhr.response ;
698+
699+ var len = uInt8Array.byteLength ;
700+ var fileOnWasmHeap = _malloc (len + 4 );
701+
702+ var properArray = new Uint8Array (uInt8Array);
703+
704+ for (var iii = 0 ; iii < len; iii++) {
705+ Module.HEAPU8 [iii + fileOnWasmHeap + 4 ] = properArray[iii];
706+ }
707+ var LEN123 = new Uint8Array (4 );
708+ LEN123[0 ] = len % 256 ;
709+ len -= LEN123[0 ];
710+ len /= 256 ;
711+ LEN123[1 ] = len % 256 ;
712+ len -= LEN123[1 ];
713+ len /= 256 ;
714+ LEN123[2 ] = len % 256 ;
715+ len -= LEN123[2 ];
716+ len /= 256 ;
717+ LEN123[3 ] = len % 256 ;
718+ len -= LEN123[3 ];
719+ len /= 256 ;
720+ Module.HEAPU8 .set (LEN123, fileOnWasmHeap);
721+ return fileOnWasmHeap;
722+ },
723+ path.c_str (), n, z, " HEAD" );
724+ // clang-format on
725+
726+ i = 0 ;
727+ for (auto h : info.headers ) {
728+ free (z[i]);
729+ i++;
730+ free (z[i]);
731+ i++;
732+ }
733+ free (z);
734+
735+ if (!exe) {
736+ res = make_uniq<HTTPResponse>(HTTPStatusCode::NotFound_404);
737+ res->reason = " Please consult the browser console for details, might be potentially a CORS error" ;
738+ } else {
739+ res = duckdb::make_uniq<HTTPResponse>(HTTPStatusCode::OK_200);
740+ uint64_t LEN = 0 ;
741+ LEN *= 256 ;
742+ LEN += ((uint8_t *)exe)[3 ];
743+ LEN *= 256 ;
744+ LEN += ((uint8_t *)exe)[2 ];
745+ LEN *= 256 ;
746+ LEN += ((uint8_t *)exe)[1 ];
747+ LEN *= 256 ;
748+ LEN += ((uint8_t *)exe)[0 ];
749+ res->body = string (exe + 4 , LEN);
750+ /*
751+ if (info.content_handler) {
752+ info.content_handler((const unsigned char *)exe + 4, LEN);
753+ }
754+ */
755+
756+ free (exe);
757+ }
758+
759+ return res;
760+ }
617761
618762 private:
619763 optional_ptr<HTTPState> state;
0 commit comments