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

More lazy loading in HTTPServerRequest #1801

Merged
merged 1 commit into from
Jul 5, 2017

Conversation

wilzbach
Copy link
Member

@wilzbach wilzbach commented Jun 29, 2017

Similarly to #1677

Some values are actually a bit problematic thanks to D's type concept (mutable methods!), for example consider the method fullURL method:

@property URL fullURL()
const @safe {
     URL url;
...
	url.username = this.username; //  Error: mutable method vibe.http.server.HTTPServerRequest.username is not callable using a const object
	url.password = this.password; //  Error: mutable method vibe.http.server.HTTPServerRequest.password is not callable using a const object
        return url;
}

I initially had the idea to hack the type system with something like assumeConst:

import std.traits;
private auto assumeConst(T)(T t) @trusted
    if (isFunctionPointer!T || isDelegate!T)
{
    enum attrs = functionAttributes!T | FunctionAttribute.const_;
    return cast(SetFunctionAttributes!(T, functionLinkage!T, attrs)) t;
}

But. of course, without success

private Nullable!FormFields _form;

private void parseFormAndFiles() @safe {
parseFormData(_form, _files, contentType, bodyReader, MaxHTTPHeaderLineLength);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I'm not overlooking something, I think this needs to set _form to .init first, or it would try to access the null field.

@wilzbach wilzbach force-pushed the more-lazy-loading branch from 2065662 to 6859939 Compare July 4, 2017 09:12
@wilzbach
Copy link
Member Author

wilzbach commented Jul 4, 2017

If I'm not overlooking something, I think this needs to set _form to .init first, or it would try to access the null field.

Excellent catch! Fixed.

@s-ludwig s-ludwig merged commit f40cf2e into vibe-d:master Jul 5, 2017
@wilzbach wilzbach deleted the more-lazy-loading branch July 6, 2017 01:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants