diff modules/http.tp @ 153:075b1e71feff

A little more work on the HTTP module
author Mike Pavone <pavone@retrodev.com>
date Fri, 09 Aug 2013 21:01:11 -0700
parents 7f442b3e4448
children 55e0dca7d3d7
line wrap: on
line diff
--- a/modules/http.tp	Fri Aug 09 20:12:04 2013 -0700
+++ b/modules/http.tp	Fri Aug 09 21:01:11 2013 -0700
@@ -4,9 +4,33 @@
 			get <- :path {
 				sock <- socket connectTo: address onPort: port
 				sock send: "GET " . path . " HTTP/1.1\r\nHost: " . address . "\r\n\r\n"
-				resp <- sock recv 4096
-				print: resp
+				resp <- ""
+				waiting <- true
+				headerText <- ""
+				rest <- ""
+				while: { waiting } do: {
+					data <- sock recv 4096
+					resp <- resp . data
+					pos <- resp find: "\r\n\r\n" else: { -1 }
+					if: pos >= 0 {
+						waiting <- false
+						headerText <- resp from: 0 withLength: pos
+						rest <- resp from: pos + 4
+					}
+				}
+				print: "Headers:\n" . headerText . "\n"
+				print: "Rest:\n" . rest . "\n"
+				_headers <- (headerText split: "\r\n") fold: (dict linear) with: :acc curLine{
+					//TODO: support multiple headers with the same name
+					part <- curLine partitionOn: ":"
+					acc set: (part before) (trim: (part after))
+				}
+				_closed <- false
+				#{
+
+				}
 				sock close
+				rest
 			}
 		}
 	}