changeset 1119:951fced704d6

Basis.textBlob; support HTTP requests with no headers
author Adam Chlipala <adamc@hcoop.net>
date Tue, 05 Jan 2010 15:53:35 -0500
parents 87b0a9d08e73
children 74f2eb3b0606
files include/urweb.h lib/ur/basis.urs src/c/http.c src/c/urweb.c
diffstat 4 files changed, 13 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/include/urweb.h	Tue Jan 05 14:57:35 2010 -0500
+++ b/include/urweb.h	Tue Jan 05 15:53:35 2010 -0500
@@ -215,6 +215,7 @@
 uw_Basis_string uw_Basis_fileMimeType(uw_context, uw_Basis_file);
 uw_Basis_blob uw_Basis_fileData(uw_context, uw_Basis_file);
 uw_Basis_int uw_Basis_blobSize(uw_context, uw_Basis_blob);
+uw_Basis_blob uw_Basis_textBlob(uw_context, uw_Basis_string);
 
 __attribute__((noreturn)) void uw_return_blob(uw_context, uw_Basis_blob, uw_Basis_string mimeType);
 __attribute__((noreturn)) void uw_redirect(uw_context, uw_Basis_string url);
--- a/lib/ur/basis.urs	Tue Jan 05 14:57:35 2010 -0500
+++ b/lib/ur/basis.urs	Tue Jan 05 15:53:35 2010 -0500
@@ -704,6 +704,7 @@
 val checkMime : string -> option mimeType
 val returnBlob : t ::: Type -> blob -> mimeType -> transaction t
 val blobSize : blob -> int
+val textBlob : string -> blob
 
 con radio = [Body, Radio]
 val radio : formTag string radio [Id = string]
--- a/src/c/http.c	Tue Jan 05 14:57:35 2010 -0500
+++ b/src/c/http.c	Tue Jan 05 15:53:35 2010 -0500
@@ -147,12 +147,17 @@
           }
         }
 
+        body[-4] = '\r';
+        body[-3] = '\n';
+
         if (!(s = strstr(buf, "\r\n"))) {
           fprintf(stderr, "No newline in request\n");
           close(sock);
           goto done;
         }
 
+        body[-4] = body[-3] = 0;
+
         *s = 0;
         headers = s + 2;
         method = s = buf;
--- a/src/c/urweb.c	Tue Jan 05 14:57:35 2010 -0500
+++ b/src/c/urweb.c	Tue Jan 05 15:53:35 2010 -0500
@@ -3131,6 +3131,12 @@
   return b.size;
 }
 
+uw_Basis_blob uw_Basis_textBlob(uw_context ctx, uw_Basis_string s) {
+  uw_Basis_blob b = {strlen(s), s};
+
+  return b;
+}
+
 uw_Basis_blob uw_Basis_fileData(uw_context ctx, uw_Basis_file f) {
   return f.data;
 }