Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

http.server: handle an empty Json body #2042

Merged
merged 1 commit into from May 18, 2018

Conversation

Projects
None yet
3 participants
@wilzbach
Copy link
Member

wilzbach commented Jan 22, 2018

If req.json is called on an empty Json body, it throws an error message which
is rather hard to understand for the casual observer:

core.exception.AssertError@/usr/include/dlang/dmd/std/typecons.d(2583): Called `get' on null Nullable!Json.
----------------
??:? _d_assert_msg [0xb539aeea]
??:? inout pure nothrow ref @property @nogc @safe inout(vibe.data.json.Json) std.typecons.Nullable!(vibe.data.json.Json).Nullable.get() [0xb5224d99]
??:? ref @property @safe vibe.data.json.Json vibe.http.server.HTTPServerRequest.json() [0xb521431d]
??:? void app.handler(scope vibe.http.server.HTTPServerRequest, vibe.http.server.HTTPServerResponse) [0xb51e4b4e]
??:? @trusted void vibe.http.server.listenHTTP!(vibe.http.server.HTTPServerSettings).listenHTTP(vibe.http.server.HTTPServerSettings, void function(scope vibe.http.server.HTTPServerRequest, vibe.http.server.HTTPServerResponse)*).__lambda3!(vibe.http.server.HTTPServerRequest, vibe.http.server.HTTPServerResponse).__lambda3(scope vibe.http.server.HTTPServerRequest, scope vibe.http.server.HTTPServerResponse) [0xb51eea3b]
??:? @safe bool vibe.http.server.handleRequest(vibe.internal.interfaceproxy.InterfaceProxy!(vibe.core.stream.Stream).InterfaceProxy, vibe.core.net.TCPConnection, vibe.http.server.HTTPServerContext, ref vibe.http.server.HTTPServerSettings, ref bool, scope stdx.allocator.IAllocator) [0xb5286a8d]
??:? @trusted void vibe.http.server.handleHTTPConnection(vibe.core.net.TCPConnection, vibe.http.server.HTTPServerContext).__lambda4() [0xb5284f46]
??:? @safe void vibe.http.server.handleHTTPConnection(vibe.core.net.TCPConnection, vibe.http.server.HTTPServerContext) [0xb5284c57]
??:? nothrow @safe void vibe.http.server.listenHTTPPlain(vibe.http.server.HTTPServerSettings, void delegate(vibe.http.server.HTTPServerRequest, vibe.http.server.HTTPServerResponse) @safe).doListen(vibe.http.server.HTTPServerContext, bool, bool).__lambda4(vibe.core.net.TCPConnection) [0xb52185a5]
??:? void vibe.core.task.TaskFuncInfo.set!(void delegate(vibe.core.net.TCPConnection) @safe, vibe.core.net.TCPConnection).set(ref void delegate(vibe.core.net.TCPConnection) @safe, ref vibe.core.net.TCPConnection).callDelegate(ref vibe.core.task.TaskFuncInfo) [0xb5351580]
??:? void vibe.core.task.TaskFuncInfo.call() [0xb533184d]
??:? nothrow void vibe.core.task.TaskFiber.run() [0xb5330e65]
??:? void core.thread.Fiber.run() [0xb53e7edb]
??:? fiber_entryPoint [0xb53e7daa]
??:? [0xffffffff]
name "tests"
description "Receive an empty JSON body"
dependency "vibe-d:http" path="../../"
versions "VibeDefaultMain"

This comment has been minimized.

@ZombineDev

ZombineDev Jan 23, 2018

Contributor

remove


import std.conv : to;

shared static this()

This comment has been minimized.

@ZombineDev

ZombineDev Jan 23, 2018

Contributor

void main()

assert(false, e.msg);
}
});
}

This comment has been minimized.

@ZombineDev

ZombineDev Jan 23, 2018

Contributor

And perhaps runEventLoop() before the end of main?

@wilzbach wilzbach force-pushed the wilzbach:json-empty-body branch from df956ea to d924091 Feb 23, 2018

@wilzbach

This comment has been minimized.

Copy link
Member Author

wilzbach commented Feb 23, 2018

(remove VibeDefaultMain)

@s-ludwig s-ludwig merged commit 422a3a3 into vibe-d:master May 18, 2018

3 checks passed

codecov/patch 100% of diff hit (target 58.243%)
Details
continuous-integration/appveyor/pr AppVeyor build succeeded
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.