RejectedSoftware Forums

Sign up

Request method called twice

This is the example hello world.

import vibe.d;
import std.file;
import std.stdio;

int c = 0;

shared static this()
{

auto settings = new HTTPServerSettings;
settings.port = 8080;
settings.bindAddresses = ["::1", "127.0.0.1"];
listenHTTP(settings, &hello);

logInfo("Please open http://127.0.0.1:8080/ in your browser.");

}

void hello(HTTPServerRequest req, HTTPServerResponse res)
{

string str = format("Count: %d", c++);

writefln("%s", str);
res.writeBody(str);
writefln("%s", str);

}

/*

Console output:

Listening for HTTP requests on ::1:8080
Listening for HTTP requests on 127.0.0.1:8080
Please open http://127.0.0.1:8080/ in your browser.
Count: 0
Count: 0
Count: 1
Count: 1

*/

The method hello is called twice, though there is only one response.

Re: Request method called twice

Am 29.04.2014 11:45, schrieb Chris Rays:

This is the example hello world.

(...)

The method hello is called twice, though there is only one response.

Can you try to print the content of req.requestURL, too? I suspect
that the browser is requesting something like "/favicon.ico" or similar.

Re: Request method called twice

On Tue, 29 Apr 2014 14:42:43 +0200, Sönke Ludwig wrote:

Am 29.04.2014 11:45, schrieb Chris Rays:

This is the example hello world.

(...)

The method hello is called twice, though there is only one response.

Can you try to print the content of req.requestURL, too? I suspect
that the browser is requesting something like "/favicon.ico" or similar.

Yes. That is exactly the case.