net-http-server icon indicating copy to clipboard operation
net-http-server copied to clipboard

How do I use the Rack handler?

Open rkh opened this issue 12 years ago • 4 comments

rackup -s HTTP doesn't work (I think rack is trying to load rack/handler/hTTP.rb), neither does rackup -s http, as you don't call register in the handler.

rkh avatar May 13 '12 18:05 rkh

Hmm rackup -s HTTP works for me (net-http-server 0.2.1). Although, it's returning Chunked Transfer-Encoding lines.

postmodern avatar Jun 02 '12 03:06 postmodern

Isn't Transfer-Encoding a response header?

zhengjia avatar Jun 09 '12 03:06 zhengjia

Here's what I'm seeing with net-http-server 0.2.1 and rack 1.4.1:

run lambda { |env|
  [200, {'Content-Type' => 'text/html'}, ['hello world']]
}
$ rackup -s HTTP
$ curl -v http://localhost:9292/
* About to connect() to localhost port 9292 (#0)
*   Trying 127.0.0.1... connected
* Connected to localhost (127.0.0.1) port 9292 (#0)
> GET / HTTP/1.1
> User-Agent: curl/7.21.7 (x86_64-redhat-linux-gnu) libcurl/7.21.7 NSS/3.13.3.0 zlib/1.2.5 libidn/1.22 libssh2/1.2.7
> Host: localhost:9292
> Accept: */*
> 
< HTTP/1.1 200 OK
< Content-Type: text/html
< Transfer-Encoding: chunked
< 
b
hello world
0

* Connection #0 to host localhost left intact
* Closing connection #0

postmodern avatar Jun 09 '12 03:06 postmodern

Ah it appears Rack is doing it's own Chunked Encoding:

T 127.0.0.1:49996 -> 127.0.0.1:9292 [AP]
  GET / HTTP/1.1..Accept: */*..User-Agent: Ruby..Host: localhost:9292....              
##
T 127.0.0.1:9292 -> 127.0.0.1:49996 [AP]
  HTTP/1.1 200 OK..                                                                    
##
T 127.0.0.1:9292 -> 127.0.0.1:49996 [AP]
  Content-Type: text/html..                                                            
##
T 127.0.0.1:9292 -> 127.0.0.1:49996 [AP]
  Transfer-Encoding: chunked..                                                         
##
T 127.0.0.1:9292 -> 127.0.0.1:49996 [AP]
  ..                                                                                   
##
T 127.0.0.1:9292 -> 127.0.0.1:49996 [AP]
  10..                                                                                 
##
T 127.0.0.1:9292 -> 127.0.0.1:49996 [AP]
  b..hello world..                                                                     
##
T 127.0.0.1:9292 -> 127.0.0.1:49996 [AP]
  ..                                                                                   
##
T 127.0.0.1:9292 -> 127.0.0.1:49996 [AP]
  5..                                                                                  
##
T 127.0.0.1:9292 -> 127.0.0.1:49996 [AP]
  0....                                                                                
##
T 127.0.0.1:9292 -> 127.0.0.1:49996 [AP]
  ..                                                                                   
##
T 127.0.0.1:9292 -> 127.0.0.1:49996 [AP]
  0....                                                                                

postmodern avatar Jun 09 '12 03:06 postmodern