# New Ticket Created by  Kay-Uwe Huell 
# Please include the string:  [perl #39857]
# in the subject line of all future correspondence about this issue. 
# <URL: http://rt.perl.org/rt3/Ticket/Display.html?id=39857 >


Hi parrot,

this is a patch to make examples/io/httpd.pir RFC compliant (at least
about CRLF).

I put CRLF into a constant...

Regards,

kiwi

Index: CREDITS
===================================================================
--- CREDITS	(Revision 13333)
+++ CREDITS	(Arbeitskopie)
@@ -282,6 +282,8 @@
 N: Juergen Boemmels
 D: Parrot I/O; macro stuff in assembler.
 
+N: Kay-Uwe 'kiwi' Hüll
+
 N: Kenneth A Graves
 D: yield and other PIR improvements
 
Index: examples/io/httpd.pir
===================================================================
--- examples/io/httpd.pir	(Revision 13333)
+++ examples/io/httpd.pir	(Arbeitskopie)
@@ -44,6 +44,11 @@
 
 =cut
 
+.const string CRLF = "\r\n"
+.const string CRLFCRLF = "\r\n\r\n"
+.const string LFLF = "\n\n"
+.const string CRCR = "\r\r"
+
 .sub main :main
     .local pmc sock, work, fp
     .local pmc fp               # read requested files from disk
@@ -83,15 +88,15 @@
 
     if ret <= 0 goto SERVE_REQ
     concat req, buf
-    index pos, req, "\r\n\r\n"
+    index pos, req, CRLFCRLF
     # print "\npos1:"
     # print pos
     if pos >= 0 goto SERVE_REQ
-    index pos, req, "\n\n"
+    index pos, req, LFLF
     # print "\npos2:"
     # print pos
     if pos >= 0 goto SERVE_REQ
-    index pos, req, "\r\r"
+    index pos, req, CRCR
     # print "\npos3:"
     # print pos
     if pos >= 0 goto SERVE_REQ
@@ -137,14 +142,16 @@
     unless fp goto SERVE_404
 
     read file_content, fp, 65535
-    rep = "HTTP/1.x 200 OK\n"
-    concat rep, "Server: Parrot-httpd/0.1\n"
-    concat rep, "Content-Length: "
+    rep = "HTTP/1.x 200 OK"
+    rep .= CRLF
+    rep .= "Server: Parrot-httpd/0.1"
+    rep .= CRLF
+    rep .= "Content-Length: "
     length len, file_content
     temp = to_string (len)
-    concat rep, temp
-    concat rep, "\n\n"
-    concat rep, file_content
+    rep .= temp
+    rep .= CRLFCRLF
+    rep .= file_content
     send ret, work, rep
     print "served file '"
     print url
@@ -152,12 +159,16 @@
     goto NEXT
 
 SERVE_docroot:
-    rep = "HTTP1/1 301 Moved Permamently\nLocation: /docs/html/index.html\nContent-Length: "
+    rep = 'HTTP1/1 301 Moved Permamently'
+    rep .= CRLF
+    rep .= 'Location: /docs/html/index.html'
+    rep .= CRLF
+    rep .= 'Content-Length: '
     file_content = "Please go to <a href='docs/html/index.html'>Parrot Documentation</a>." 
     length len, file_content
     temp = to_string (len)
     concat rep, temp
-    concat rep, "\n\n"
+    concat rep, CRLFCRLF
     concat rep, file_content
     send ret, work, rep
     print "Redirect to 'docs/html/index.hmtl'\n"
@@ -168,7 +179,17 @@
     goto SERVE_file
 
 SERVE_404:
-    rep = "HTTP1/1 404 Not Found\nContent-Length: 3\n\n404\n"
+    $S0 = '404 Not found'
+    $I0 = length $S0
+    rep = 'HTTP1/1 404 Not Found'
+    rep .= CRLF
+    rep .= 'Content-Length: '
+    $S1 = $I0
+    rep .= $S1
+    rep .= CRLF
+    rep .= 'Content-Type: text/plain'
+    rep .= CRLFCRLF
+    rep .= $S0
     print "File not found: '"
     print url
     print "'\n"

Reply via email to