Skip to content

vibe.web.rest: Vibe should return 204, not 200, when Content-Length: 0 #2831

@Geod24

Description

@Geod24
/+ dub.json: {
      "name": "test-rest",
      "dependencies": {
        "vibe-d": "~>0.10"
      }
    }
 +/
module server;

import vibe.core.core;
import vibe.core.log;
import vibe.http.client;
import vibe.http.router;
import vibe.http.server;
import vibe.web.rest;

import std.stdio;

interface API {
    void postKeepalive () @safe;
}

class Server : API {
    override void postKeepalive () @safe {
        logInfo("Ping!");
    }
}

int main () {
    scope serv = new Server();
    auto router = new URLRouter();
    router.registerRestInterface(serv);
    runTask(() @safe nothrow {
        scope (failure) assert(0);
        requestHTTP("http://127.0.0.1:4242/keepalive",
            (scope req) {
                req.method = HTTPMethod.POST;
            },
            (scope res) {
                logInfo("Response status: %s", res.statusCode);
                logInfo("Response headers: %s", res.headers);
            });
    });
    listenHTTP("127.0.0.1:4242", router);
    return runEventLoop();
}
 % dub --single server.d
[...]
     Running test-rest
Listening for requests on http://127.0.0.1:4242/
Ping!
Response status: 200
Response headers: ["Server": "vibe.d/2.13.0", "Date": "Sun, 31 Aug 2025 15:44:41 GMT", "Keep-Alive": "timeout=10", "Content-Type": "application/octet-stream", "Content-Length": "0"]

I would expect Vibe.d to return a 204 when the return type of a POST method is void.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions