Hacker Newsnew | past | comments | ask | show | jobs | submit | 2010-11-09login
Stories from November 9, 2010
Go back a day, month, or year. Go forward a day, month, or year.
1.⌘Q is too damn close to ⌘W (squishtech.posterous.com)
226 points by sprsquish on Nov 9, 2010 | 106 comments
2.World's largest association of pilots boycotts body scanners (bigbrotherwatch.org.uk)
220 points by mcantelon on Nov 9, 2010 | 109 comments
3.We're moving. Goodbye Rackspace. (mixpanel.com)
203 points by suhail on Nov 9, 2010 | 174 comments
4.Wherein I help you get a good job (aaronboodman.com)
185 points by malbiniak on Nov 9, 2010 | 94 comments
5.Using MySQL as a NoSQL - A story for exceeding 750,000 qps on a commodity server (yoshinorimatsunobu.blogspot.com)
169 points by davecardwell on Nov 9, 2010 | 31 comments
6.Japan's Latest Rock Star Is A 3D Hologram - Draws Huge Crowds (singularityhub.com)
169 points by kkleiner on Nov 9, 2010 | 70 comments
7.Turns out, it is a river in Egypt (discovermagazine.com)
167 points by chanux on Nov 9, 2010 | 42 comments
8.When we have money we'll do X (antoniocangiano.com)
161 points by acangiano on Nov 9, 2010 | 29 comments
9.Daring Fireball: Apple's Pricing Advantage (daringfireball.net)
146 points by motvbi on Nov 9, 2010 | 173 comments
10.1.0 Is The Loneliest Number (ma.tt)
142 points by powdahound on Nov 9, 2010 | 27 comments
11.1140px grid system. Time to scrap 960px? (cssgrid.net)
131 points by ramxpa on Nov 9, 2010 | 65 comments
12.Backbone.js adds Controllers and History (documentcloud.github.com)
125 points by raganwald on Nov 9, 2010 | 25 comments
13.What Alcohol Actually Does to Your Brain and Body (lifehacker.com)
123 points by ArturSoler on Nov 9, 2010 | 48 comments
14.Rob Pike: Notes on Programming in C (liu.se)
122 points by ssp on Nov 9, 2010 | 111 comments
15.Facebook Finds A New Way To Liberate Your Gmail Contact Data (techcrunch.com)
116 points by stevederico on Nov 9, 2010 | 81 comments
16.Mystery Missile Launch Seen off California Coast (cbsnews.com)
109 points by ph0rque on Nov 9, 2010 | 85 comments
17.Your Bank Balance is at Zero (ideasonideas.com)
106 points by karjaluoto on Nov 9, 2010 | 76 comments
18.HTML5 boilerplate (html5boilerplate.com)
97 points by epo on Nov 9, 2010 | 14 comments
19.Show HN: Spreadsheets using Python - Have you seen this? (sourceforge.net)
97 points by nickpinkston on Nov 9, 2010 | 47 comments
20.Leading scientists say backscatter X-ray may be far more dangerous than thought (npr.org)
91 points by zacharyvoase on Nov 9, 2010 | 50 comments

The problem appears to be in srv.arc where there's the following:

  (def gen-type-header (ctype)
    (+ "HTTP/1.0 200 OK
  Content-Type: "
       ctype
       "
  Connection: close"))
hexl-mode on the file shows that those line endings are 0x0A:

  00001630: 2874 6162 6c65 2929 0a0a 2864 6566 2067 (table))..(def g
  00001640: 656e 2d74 7970 652d 6865 6164 6572 2028  en-type-header (
  00001650: 6374 7970 6529 0a20 2028 2b20 2248 5454  ctype).  (+ "HTT
  00001660: 502f 312e 3020 3230 3020 4f4b 0a43 6f6e  P/1.0 200 OK.Con
  00001670: 7465 6e74 2d54 7970 653a 2022 0a20 2020  tent-Type: ".
  00001680: 2020 6374 7970 650a 2020 2020 2022 0a43    ctype.     ".C
  00001690: 6f6e 6e65 6374 696f 6e3a 2063 6c6f 7365  onnection: close
  000016a0: 2229 290a 0a28 6d61 7020 2866 6e20 2828  "))..(map (fn ((
Eventually the headers get printed to the socket via prn:

          (let filetype (static-filetype op)
             (aif (and filetype (file-exists (string staticdir* op)))
                  (do (prn (type-header* filetype))
prn is defined in arc.arc

  (def pr args
    (map1 disp args)
    (car args))

  (def prn args
    (do1 (apply pr args)
         (pr #\newline))) ; writec doesn't implicitly flush
which is using disp which is defined in ac.scm

  (define (printwith f args)u  (let ((port (if (> (length args) 1)
                    (cadr args)
                    (current-output-port))))
      (when (pair? args)
        (f (ac-denil (car args)) port))
      (unless (ar-bflag 'explicit-flush)
        (flush-output port)))
    'nil)

  (defarc write (arc-write . args) (printwith write args))
  (xdef disp  (lambda args (printwith display args)))
That's using the MzScheme display method which appears to just do writing of bytes and doesn't do any CRLF translation (http://docs.racket-lang.org/reference/Writing.html?q=display...)

Quick verification of that:

  $ cat test.scm
  (display "Hello, World!")
  (display #\return)
  (display  #\newline)
  $ mzscheme -r test.scm | hexdump -C
  00000000  48 65 6c 6c 6f 2c 20 57  6f 72 6c 64 21 0d 0a     |Hello, World!..|
So, there are a couple of possible solutions: explicitly specify CRLF as line endings when needed (i.e. insert #\return), or have a special version of pr for network communication that does LF -> CRLF translation).

Within the respond function there are other instances of using prn to send to the socket that need to be fixed:

  (def respond (str op args cooks clen ctype in ip)
    (w/stdout str
      (iflet f (srvops* op)
             (let req (inst 'request 'args args 'cooks cooks 'ctype ctype
             'clen clen 'in in 'ip ip)
               (if (redirector* op)
                   (do (prn rdheader*)
                       (prn "Location: " (f str req))
                       (prn))
                   (do (prn header*)
                       (awhen (max-age* op)
                         (prn "Cache-Control: max-age=" it))
                       (f str req))))
             (let filetype (static-filetype op)
               (aif (and filetype (file-exists (string staticdir* op)))
                    (do (prn (type-header* filetype))
                        (awhen static-max-age*
                          (prn "Cache-Control: max-age=" it)) 
                        (prn)
                        (w/infile i it
                          (whilet b (readb i)
                            (writeb b str))))
                    (respond-err str unknown-msg*))))))
I'm guessing that altering gen-type-header and creating a special prcrlf function is the way to go.

  (def prcrlf args
    (do1 (apply pr args)
         (pr #\return)
         (pr #\newline)))

  (def gen-type-header (ctype)
    (+ "HTTP/1.0 200 OK#\return
  Content-Type: "
       ctype
       "#\return
  Connection: close"))
Although, personally, I don't like the assumption that the editor is inserting 0x0A for line-endings and would rather be totally certain with something like:

  (def gen-type-header (ctype)
    (+ "HTTP/1.0 200 OK"
       #\return #\newline
       "Content-Type: "
       ctype
       #\return #\newline
       "Connection: close"))
Since you'll need to do this sort of thing a lot a little helper would probably make sense (and I'd add the CRLF on the last line explicitly):

  (def crlf (a)
    (+ a #\return #\newline))

  (def gen-type-header (ctype)
    (+ (crlf "HTTP/1.0 200 OK")
       (crlf (+ "Content-Type: " ctype))
       (crlf "Connection: close")))
And change every instance of prn in respond to prcrlf. Except for (prn (type-header* filetype)) which becomes (pr (type-header* filetype)).

Note: I have not tested this change. Probably some other small gotchas.

22.ASP.NET MVC 3 Release Candidate (asp.net)
71 points by bsk on Nov 9, 2010 | 44 comments
23.What do YC Founders think about working at Big Companies? (rahfeedback.posterous.com)
72 points by dayjah on Nov 9, 2010 | 40 comments
24.Facebook Slaps Google: “Openness Doesn’t Mean Being Open When It’s Convenient” (techcrunch.com)
72 points by michaelhart on Nov 9, 2010 | 63 comments
25.17% leave their job due to insufficient recognition (rypple.com)
69 points by jsatok on Nov 9, 2010 | 66 comments
26.Why 'Be Passionate' Is Awful Advice (inc.com)
68 points by frankdenbow on Nov 9, 2010 | 34 comments
27.Lisp has too many parentheses... (symbo1ics.com)
66 points by zephyrfalcon on Nov 9, 2010 | 77 comments

29.Twilio Raises $12 Million For Powerful Telephony API (techcrunch.com)
63 points by gspyrou on Nov 9, 2010 | 35 comments
30.By example: Continuation-passing style in JavaScript (might.net)
62 points by budu on Nov 9, 2010 | 19 comments

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: