Thanks Greg. Here's a variation that gives a little more insight.

#lang racket

(require net/url)

(with-handlers ([(lambda (x)  #t)
                 (lambda (x) (printf "Oops!"))])
(purify-port (head-impure-port (string->url "http://www.racket-lang.org";))) )


I repeatedly run this. In all cases a header string is returned from the server. Sometimes it's a 505 error. Sometimes it's "HTTP/1.1 400 Bad Request ..." and that's when I also see the contract violation. However no exception is ever caught by the with-handlers. Since I can't catch the exception I guess it is being logged from a separate thread?

As you say, some sort of error message is appropriate, at least from the server. But the contract violation makes no sense to me. That must be a bug I think.



On 10/16/2015 10:17 AM, Greg Hendershott wrote:
The URL needs to get split into parts, and the HTTP request will go
"on the wire" as something like:

     HEAD <path> HTTP/1.0
     Host: www.racket-lang.org
     <more headers>

When you have the trailing / it will be:

     HEAD / HTTP/1.0

Which makes sense.

When the trailing slash is missing, i.e. "no path", I'm guessing that
http-conn-send! is sending

     HEAD HTTP/1.0

The server thinks the path is "HTTP/1.0" and the HTTP/<ver> part is...
missing. The server doesn't think blank is a valid version of HTTP. It
may have a point. :)

TL;DR1: It's probably good form to use the trailing slash in your
URLs, anyway. (What you can type in a browser address bar is a lot
looser than what you can/should use in code.)  This will work even
with the currently shipping Racket.

TL;DR2: Jay, http-conn-send! might want to supply "/" when the path is
missing?  Or at least something like (error 'http-conn-send! "URL is
missing a path") so it fails more understandably?



On Fri, Oct 16, 2015 at 6:18 AM, Jon Stenerson <jonstener...@comcast.net> wrote:
This works:

(define p (head-impure-port (string->url "http://www.racket-lang.org/";)))
(read-line p)
"HTTP/1.1 200 OK\r"

But, leaving off trailing /, I usually see

(define p (head-impure-port (string->url "http://www.racket-lang.org";)))
string-trim: contract violation
   expected: string?
   given: #<eof>

Sometimes I get a port with status line "HTTP/1.1 505 HTTP Version not
supported\r".

Can anyone explain? Thanks.

--
You received this message because you are subscribed to the Google Groups
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an
email to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Racket 
Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to