macournoyer/thin — Issue #84: Cannot use thin with netcat for debugging
Author: leehambley
Created: 2012-01-23 21:19:55+00:00
State: open

I'm experimenting with Thin as webserver for a project that I am working on.

Here's the situation, I'm experimenting posting to the API I have written with raw sockets in C. I can't say much about how that's working as I am quite inexperienced, however here are my observations. (using netcat)

``` ruby
# config.ru
class SimplestThingThatCouldPossiblyWork
def call(env)
[200, {'Content-Type' => 'text'}, ['200 OK'] ]
end
end
run SimplestThingThatCouldPossiblyWork.new
```

``` text
# First terminal
$ thin start
```

``` text
# second terminal
$ echo "GET / HTTP/1.1\n" | nc watched.it.local 3000
```

Immediately visible in the first terminal is the:

``` text
$ thin start
>> Using rack adapter
>> Thin web server (v1.2.11 codename Bat-Shit Crazy)
>> Maximum connections set to 1024
>> Listening on 0.0.0.0:3000, CTRL+C to stop
"GET / HTTP/1.1\\n\n"
!! Invalid request
``

(note I modified the `rescue InvalidRequest` to dump `data.inspect`)

However, the same with mongrel yields "Timeout Error" (naturally, I didn't finish sending headers…) - and when I do complete the headers it works correctly.

Ordinarily I would assume I was doing something drastically wrong with my socket code, but in this instance as `nc` is also failing, and a known-good implementation of the C code (from an experienced friend) is also failing, I'll assume it's something about thin reading input linewise or, assuming that the whole input comes in one packet(?) but I'm really guessing and out of my league here.