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

REST enhancement #1: Allow one to get parameters from headers #908

Merged
merged 12 commits into from
Dec 11, 2014

Conversation

Geod24
Copy link
Contributor

@Geod24 Geod24 commented Dec 1, 2014

As the title say, I reopen #867 here.
I accidentally deleted my (remote) branch, and Github won't let me re-open the P.R.

I re-pushed original code to #867 . This one is rebased (because of #871 ).

The only change from #867 is that I renamed @fromHeader to @headerParam.
I can revert that if needed, but I think we have 2 advantages here:

Pinging @Dicebot .

- Add a string[string] headers__ local variable to the generated function;
- If there's one and only one WebParamAttribute with the name of the parameter we're currently processing (as parameter gets processed in order), we add it to the AA, the key being the 'field' in WebParamAttribute;
- headers__ gets later passed to request() which will add all it's field to the headers;
@Geod24 Geod24 force-pushed the rest-enh-unsplit-2 branch from 635f272 to ca950a3 Compare December 1, 2014 21:07
@Geod24
Copy link
Contributor Author

Geod24 commented Dec 2, 2014

For the record, my unittests are here:
https://github.com/Geod24/vibe.d/tree/rest-unittests

(under tests/rest/parameter/)

Not complete yet though. And I got a cryptic linker failure when running dub test (DMD 2.066, SEGV with GDC 4.9...).

/usr/include/dlang/dmd/std/array.d:62: error: undefined reference to '_D3std9algorithm463__T12FilterResultS4364vibe3web4rest109__T21registerRestInterfaceTC5tests4rest10parameters6source3app16__unittestL167_2FZ24TestHeaderParamMisconfigZ21registerRestInterfaceFC4vibe4http6router9URLRouterC5tests4rest10parameters6source3app16__unittestL167_2FZ24TestHeaderParamMisconfigC4vibe3web4rest21RestInterfaceSettingsZ8addRouteMFE4vibe4http6common10HTTPMethodAyaDFC4vibe4http6server17HTTPServerRequestC4vibe4http6server18HTTPServerResponseZvAAyaZ9__lambda5TAAyaZ12FilterResult7opSliceMFNaNbNiNfZS3std9algorithm463__T12FilterResultS4364vibe3web4rest109__T21registerRestInterfaceTC5tests4rest10parameters6source3app16__unittestL167_2FZ24TestHeaderParamMisconfigZ21registerRestInterfaceFC4vibe4http6router9URLRouterC5tests4rest10parameters6source3app16__unittestL167_2FZ24TestHeaderParamMisconfigC4vibe3web4rest21RestInterfaceSettingsZ8addRouteMFE4vibe4http6common10HTTPMethodAyaDFC4vibe4http6server17HTTPServerRequestC4vibe4http6server18HTTPServerResponseZvAAyaZ9__lambda5TAAyaZ12FilterResult'
/usr/include/dlang/dmd/std/array.d:62: error: undefined reference to '_D3std9algorithm463__T12FilterResultS4364vibe3web4rest109__T21registerRestInterfaceTC5tests4rest10parameters6source3app16__unittestL167_2FZ24TestHeaderParamMisconfigZ21registerRestInterfaceFC4vibe4http6router9URLRouterC5tests4rest10parameters6source3app16__unittestL167_2FZ24TestHeaderParamMisconfigC4vibe3web4rest21RestInterfaceSettingsZ8addRouteMFE4vibe4http6common10HTTPMethodAyaDFC4vibe4http6server17HTTPServerRequestC4vibe4http6server18HTTPServerResponseZvAAyaZ9__lambda5TAAyaZ12FilterResult5emptyMFNaNbNdNiNfZb'
/usr/include/dlang/dmd/std/array.d:62: error: undefined reference to '_D3std9algorithm463__T12FilterResultS4364vibe3web4rest109__T21registerRestInterfaceTC5tests4rest10parameters6source3app16__unittestL167_2FZ24TestHeaderParamMisconfigZ21registerRestInterfaceFC4vibe4http6router9URLRouterC5tests4rest10parameters6source3app16__unittestL167_2FZ24TestHeaderParamMisconfigC4vibe3web4rest21RestInterfaceSettingsZ8addRouteMFE4vibe4http6common10HTTPMethodAyaDFC4vibe4http6server17HTTPServerRequestC4vibe4http6server18HTTPServerResponseZvAAyaZ9__lambda5TAAyaZ12FilterResult5frontMFNaNbNcNdNiNfZAya'
/usr/include/dlang/dmd/std/array.d:62: error: undefined reference to '_D3std9algorithm463__T12FilterResultS4364vibe3web4rest109__T21registerRestInterfaceTC5tests4rest10parameters6source3app16__unittestL167_2FZ24TestHeaderParamMisconfigZ21registerRestInterfaceFC4vibe4http6router9URLRouterC5tests4rest10parameters6source3app16__unittestL167_2FZ24TestHeaderParamMisconfigC4vibe3web4rest21RestInterfaceSettingsZ8addRouteMFE4vibe4http6common10HTTPMethodAyaDFC4vibe4http6server17HTTPServerRequestC4vibe4http6server18HTTPServerResponseZvAAyaZ9__lambda5TAAyaZ12FilterResult8popFrontMFNaNbNiNfZv'
collect2: error: ld returned 1 exit status

Will check what's going on.

EDIT 437: Sooooooo, Vibe.d doesn't compile with DMD master. Will work on it.

@mihails-strasuns
Copy link
Contributor

Re-reading (because I have forgotten everything, doh)

@Geod24
Copy link
Contributor Author

Geod24 commented Dec 5, 2014

@Dicebot : Was the code that bad ? ;-)

@mihails-strasuns
Copy link
Contributor

No, sorry, I have read it through once to actually remember what we are speaking about and now I need time to actually do line-by-line implementation review. Hopefully this weekend.

@mihails-strasuns
Copy link
Contributor

Good. There are plenty of comments but those are mostly matter of style and naming - actual feature looks useful and solid.

@Geod24 Geod24 force-pushed the rest-enh-unsplit-2 branch 3 times, most recently from 42fc57b to f6f41cd Compare December 6, 2014 23:40
@Geod24
Copy link
Contributor Author

Geod24 commented Dec 6, 2014

Thanks for the review ! I fixed the style issues.

What's left is:

@mihails-strasuns
Copy link
Contributor

LGTM @s-ludwig

btw, @Geod24 I am thinking that after majority of your enhancements are merged we should go for separating/rewriting http://vibed.org/docs#rest-interface-generator into detailed guide. Something that will help answer the question "how am I supposed to use all that stuff?". Willing to join? :)

@Geod24
Copy link
Contributor Author

Geod24 commented Dec 7, 2014

Sure ! :-)
Any specific milestone in mind ?

@mihails-strasuns
Copy link
Contributor

As soon as your planned enhancements are complete so that next vibe.d release comes with both features and explanation for them.

@mihails-strasuns
Copy link
Contributor

I'll probably start writing something based on existing stuff I know and let you eventually take it over

@Geod24
Copy link
Contributor Author

Geod24 commented Dec 7, 2014

I have something on my mind about REST paths. I'll try to formalize that and e-mail you next week. That would be one of the 2 breaking change I plan for this module (The other one being the serialization).

@@ -348,7 +350,7 @@ class RestInterfaceClient(I) : I
import vibe.data.json : Json;
import vibe.textfilter.urlencode;

Json request(string verb, string name, Json params, bool[string] param_is_json) const
Json request(string verb, string name, Json params, bool[string] param_is_json, string[string] hdrs) const
Copy link
Member

Choose a reason for hiding this comment

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

Minor: I'd use a vibe.inet.message.InetHeaderMap here for efficiency (doesn't allocate for few or no headers).

Copy link
Member

Choose a reason for hiding this comment

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

in ref InetHeaderMap that is of course..

@s-ludwig
Copy link
Member

Generally looks good AFAICS.

@Geod24
Copy link
Contributor Author

Geod24 commented Dec 11, 2014

@s-ludwig : Thanks for the suggestion, I switched to InetHeaderMap.

@s-ludwig
Copy link
Member

Okay thanks, merging (finally)!

s-ludwig added a commit that referenced this pull request Dec 11, 2014
REST enhancement #1: Allow one to get parameters from headers
@s-ludwig s-ludwig merged commit 643cf77 into vibe-d:master Dec 11, 2014
@Geod24
Copy link
Contributor Author

Geod24 commented Dec 11, 2014

Yay, thanks !

@MartinNowak
Copy link
Contributor

This broke compilation on anything but dmd-2.066.1, see https://travis-ci.org/rejectedsoftware/vibe.d/builds/44058739.

@Geod24
Copy link
Contributor Author

Geod24 commented Dec 15, 2014

Did it ?

From the error:

source/vibe/internal/meta/uda.d(30): Error: template vibe.internal.meta.uda.findNextUDA matches more than one template declaration:
    source/vibe/internal/meta/uda.d(61):findNextUDA(alias UDA, alias Symbol, long idx, bool allow_types = false)
and
    source/vibe/internal/meta/uda.d(95):findNextUDA(UDA, alias Symbol, long idx, bool allow_types = false)

It looks like it was already broken (but not noticed) before:
https://github.com/rejectedsoftware/vibe.d/blob/2dfacf9863a79ed5a749bdb647b08686ca08b110/source/vibe/internal/meta/uda.d#L28
https://github.com/rejectedsoftware/vibe.d/blob/2dfacf9863a79ed5a749bdb647b08686ca08b110/source/vibe/internal/meta/uda.d#L66

From a quick look, the fix seems trivial, will submit P.R. today. Thanks for your work on this !

@MartinNowak
Copy link
Contributor

see #927

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.

4 participants