From: Pierre-Alexandre V. <ont...@gm...> - 2011-12-29 11:14:46
|
Still playing with it, and i got a server error now, impossible to get a backtrace I get : [Thu Dec 29 12:04:27 2011] [nethttpd] [err] [127.0.0.1:54702] [POST /upload] Nethttpd: Missing response, replying 'Server Error' The change in the CGI : i have just change the line which process the post result, by printing the content let defini_CGI_Upload (cgi : Netcgi.cgi_activation) = try let out = cgi # output # output_string in let server_file arg = match arg#store with | `File fn -> fn | `Memory -> failwith "Not stored in a file" in match cgi#request_method with | `POST -> prerr_string (cgi#argument_value "content"); cgi#finalize(); () | _ -> cgi#output#output_string "Server accepts POST requests only.\n"; cgi # set_header ~cache:`No_cache ~content_type:"text/html; charset=\"iso-8859-1\"" (); cgi # output # commit_work();raise Erreur_durant_L_upload_Post with error -> cgi # output # rollback_work(); cgi # set_header ~status:`Forbidden (* Indicate the error *) ~cache:`No_cache ~content_type:"text/html; charset=\"utf-8\"" (); (* An error has happened. Generate now an error page instead of the current page. By rolling back the output buffer, any uncomitted material is deleted.*) cgi # output # output_string "While processing the request an O'Caml exception has been raised:<BR>"; cgi # output # output_string ("<TT>" ^ (Printexc.to_string error)^ (Printexc.get_backtrace ()) ^ "</TT><BR>"); (* Now commit the error page: *) cgi # output # commit_work() ; raise Erreur_durant_L_upload ;; 2011/12/29 Pierre-Alexandre Voye <ont...@gm...> > Hello, > i'm writing code to manage upload from a browser. Even if I use a > XmlHttpRequest, i cannot fully control the http request to the server > > When i try to validate it with curl i have a strange error. > Here's the curl command line (which use attached file): > curl -F "file=@404.html;filename=404.html" http://localhost:8111/upload--trace-ascii - > > I suppose Curl respect the standard. But it's certainly my code which is > not wrote like it should. > > Here's my CGI (I know I have to use NetMime, but I don't understand > enought NetMime to use it) : > > let defini_CGI_Upload (cgi : Netcgi.cgi_activation) = > try > let out = cgi # output # output_string in > let server_file arg = > match arg#store with > | `File fn -> fn > | `Memory -> failwith "Not stored in a file" in > match cgi#request_method with > | `POST -> traite_upload { nom_fichier = cgi#argument_value > "filename" ; contentType = cgi#argument_value "contentType" ; content = > cgi#argument_value "content"; filenametmp = server_file (cgi#argument > (cgi#argument_value "filename") ) } ; (*cgi#finalize();*) > | _ -> cgi#output#output_string "Server accepts POST requests > only.\n"; > > cgi # set_header ~cache:`No_cache > ~content_type:"text/html; charset=\"iso-8859-1\"" (); > cgi # output # commit_work();raise Erreur_durant_L_upload_Post > with > error -> cgi # output # rollback_work(); > > cgi # set_header > ~status:`Forbidden > ~cache:`No_cache > ~content_type:"text/html; charset=\"utf-8\"" > (); > > cgi # output # output_string "While processing the request an > O'Caml exception has been raised:<BR>"; > cgi # output # output_string ("<TT>" ^ (Printexc.to_string error)^ > (Printexc.get_backtrace ()) ^ "</TT><BR>"); > > (* Now commit the error page: *) > cgi # output # commit_work() ; raise Erreur_durant_L_upload > ;; > > Here the backtrace I have : > Not_found > Raised by primitive operation at file "map.ml", line 118, characters > 16-25. Called from file "netmime.ml", line 326, characters 14-31. > So it's in update_multiple_field method > > > > For information, here's the transcript of curl session : > > $ curl -F "file=@404.html;filename=404.html" http://localhost:8111/upload--trace-ascii - > == Info: About to connect() to localhost port 8111 (#0) > == Info: Trying ::1... == Info: Connection refused > == Info: Trying 127.0.0.1... == Info: connected > => Send header, 296 bytes (0x128) > 0000: POST /upload HTTP/1.1 > 0017: User-Agent: curl/7.23.1 (x86_64-apple-darwin11.2.0) libcurl/7.23 > 0057: .1 OpenSSL/1.0.0e zlib/1.2.5 libidn/1.22 > 0081: Host: localhost:8111 > 0097: Accept: */* > 00a4: Content-Length: 1541 > 00ba: Expect: 100-continue > 00d0: Content-Type: multipart/form-data; boundary=-------------------- > 0110: --------402388b44fe6 > 0126: > <= Recv header, 23 bytes (0x17) > 0000: HTTP/1.1 100 Continue > => Send data, 137 bytes (0x89) > 0000: ------------------------------402388b44fe6 > 002c: Content-Disposition: form-data; name="file"; filename="404.html" > 006e: Content-Type: text/html > 0087: > => Send data, 1356 bytes (0x54c) > 0000: <!doctype html>.<html>.<head>. <meta charset="utf-8">. <title> > 0040: Page Not Found :(</title>. <style>.. body { text-align: center > 0080: ;}.. h1 { font-size: 50px; text-align: center }.. span[frown] > 00c0: { transform: rotate(90deg); display:inline-block; color: #bbb; } > 0100: .. body { font: 20px Constantia, 'Hoefler Text', "Adobe Caslon > 0140: Pro", Baskerville, Georgia, Times, serif; color: #999; text-sha > 0180: dow: 2px 2px 2px rgba(200, 200, 200, 0.5); }.. ::-moz-selection > 01c0: { background:#FF5E99; color:#fff; }.. ::selection { background: > 0200: #FF5E99; color:#fff; } .. article {display:block; text-align: l > 0240: eft; width: 500px; margin: 0 auto; }.. .. a { color: rgb(36, 1 > 0280: 09, 56); text-decoration:none; }.. a:hover { color: rgb(96, 73, > 02c0: 141) ; text-shadow: 2px 2px 2px rgba(36, 109, 56, 0.5); }. </s > 0300: tyle>.</head>.<body>. <article>.. <h1>Not found <span frown > 0340: >:(</span></h1>.. <div>.. <p>Sorry, but the page you wer > 0380: e trying to view does not exist.</p>.. <p>It looks like th > 03c0: is was the result of either:</p>.. <ul>... <li>a mistype > 0400: d address</li>... <li>an out-of-date link</li>.. </ul>.. > 0440: </div>.. .. <script>.. var GOOG_FIXURL_LANG = (navig > 0480: ator.language || '').slice(0,2),...GOOG_FIXURL_SITE = location.h > 04c0: ost;.. </script>.. <script src="http://linkhelp.clients.go > 0500: ogle.com/tbproxy/lh/wm/fixurl.js"></script>. </article>.</bo > 0540: dy>.</html>. > => Send data, 48 bytes (0x30) > 0000: > 0002: ------------------------------402388b44fe6-- > <= Recv header, 24 bytes (0x18) > 0000: HTTP/1.1 403 Forbidden > <= Recv header, 42 bytes (0x2a) > 0000: Content-Type: text/html; charset="utf-8" > <= Recv header, 25 bytes (0x19) > 0000: Cache-control: no-cache > <= Recv header, 18 bytes (0x12) > 0000: Pragma: no-cache > <= Recv header, 42 bytes (0x2a) > 0000: Expires: Thu, 29 Dec 2011 09:49:25 +0000 > <= Recv header, 28 bytes (0x1c) > 0000: Transfer-Encoding: chunked > <= Recv header, 37 bytes (0x25) > 0000: Date: Thu, 29 Dec 2011 09:49:26 GMT > <= Recv header, 24 bytes (0x18) > 0000: Server: Ocamlnet/3.4.1 > == Info: HTTP error before end of send, stop sending > <= Recv header, 2 bytes (0x2) > 0000: > <= Recv data, 228 bytes (0xe4) > 0000: e0 > 0004: While processing the request an O'Caml exception has been raised > 0044: :<BR><TT>Not_foundRaised by primitive operation at file "map.ml" > 0084: , line 118, characters 16-25.Called from file "netmime.ml", line > 00c4: 326, characters 14-31.</TT><BR> > While processing the request an O'Caml exception has been > raised:<BR><TT>Not_foundRaised by primitive operation at file "map.ml", > line 118, characters 16-25 > Called from file "netmime.ml", line 326, characters 14-31 > </TT><BR><= Recv data, 2 bytes (0x2) > 0000: > == Info: transfer closed with outstanding read data remaining > == Info: Closing connection #0 > curl: (18) transfer closed with outstanding read data remaining > > > Thank you > > -- > --------------------- > https://twitter.com/#!/ontologiae/ > http://linuxfr.org/users/montaigne > > -- --------------------- https://twitter.com/#!/ontologiae/ http://linuxfr.org/users/montaigne |