OOWeb

OOWebにはめられた。
ことの経緯はこう。簡単な検索サーバが欲しくて、わざわざ Servlet/JSP Container 使うのもあれだし、自分で ServerSocket とか使ってマルチスレッドでサーバ書くのも面倒だっつうことで OOWeb を使って簡単に済ませようと思ったのだ。
で、サンプル見ながら「おぉ、簡単だ」なんて喜んでたのも束の間、レスポンスの MIME Type を変更すると動かない。MIME Type を変更するサンプルは

    public String xmlTest() {
        HTTP.setMimeType("text/xml");
        return "<?xml version=\"1.0\"?>\r\n\r\n<root><word>this</word><word>is</word><word>XML</word></root>";
    }

と超簡単。間違えようもなさげ。で、OOWeb のソースコードを追っかけると、net.sf.HTTPResponse にこんなのが。

    private void sendOk() throws ResponseCommittedException {
        startResponse(HTTPResponse.CODE_200, (mimeType != null ? mimeType : DEFAULT_MIME_TYPE));
        if(sessionCookieRequired)
            responseCookies.add(new Cookie(applicationName, StringUtils.generateUUID()));
        addCookiesToResponse();
        if (mimeType == null || mimeType.equals(DEFAULT_MIME_TYPE))
            addToResponse("");
    }

んん?mimeType が null かデフォルト値と等しいときだけ何かしている。いやな予感がする。ためしに上の xmlTest を telnet を使ってテスト。

% telnet localhost 1234
Trying 127.0.0.1...
Connected to localhost.localdomain.
Escape character is '^]'.
GET /xmlTest HTTP/1.0

HTTP/1.1 200 OK
Content-Type: text/xml
Server: OOWeb
Set-Cookie: MyOOWeb2=uuid:b30b0f01-140b-d617-66cf-7661696f6246; path=/;
<?xml version="1.0"?>

<root><word>this</word><word>is</word><word>XML</word></root>
Connection closed by foreign host.

うわー。HEADER と BODY の間に空行がはいってねー。これかー。そもそもあの if 文いらなくね?
ていうかさ、

            // Does the response from the object contain an HTTP response 
            // code? if not, we'll stick on our default 200 OK
            if(!applicationResponse.toString().startsWith("HTTP")) 
                response.sendOk(applicationResponse.toString());
            else 
                response.sendRaw(applicationResponse.toString());

これってどうよ?あ、applicationResponse ってのは上の xmlTest みたいなメソッドで返したオブジェクトね。
あぁ、しかし、これで、また TODO にバグ報告が追加ですよ。まだ python-cdb のも報告してないのに。早くしよ。