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

Status Strings for all response codes in use #13

Merged
merged 4 commits into from Jan 8, 2019

Conversation

Projects
None yet
2 participants
@dougrk
Copy link
Contributor

dougrk commented Dec 24, 2018

Changes for issue #8

@michaelneu

This comment has been minimized.

Copy link
Owner

michaelneu commented Dec 25, 2018

Thanks for the PR!

It looks quite good, but if we need more than the five most common REST status codes, we'll have to add many ElseIfs (also, it currently lacks 418, which is crucial for every webserver 😄 ).

I thought about adding a lookup-table using a CreateObject("Scripting.Dictionary"). This should scale more easily, as adding a new status code will only require adding an entry to the dictionary like m_codes.Add "200", "OK".

Would you mind adding such a dictionary or even extract this behaviour to a HttpStatusCodeCollection, and also include more status codes? HttpHeaderCollection does something rather similar, except that it can be iterated over instead of having a lookup method.

@dougrk

This comment has been minimized.

Copy link
Contributor

dougrk commented Dec 26, 2018

I also thought about using a dictionary, but I was tired and somehow came to the conclusion that I shouldn't reference the Scripting library unless it was absolutely necessary. That logic doesn't hold up 😅

I will make your proposed changes tomorrow: I am traveling for Christmas and don't have a Windows Machine to test with. Merry Christmas! 🎄

@dougrk

This comment has been minimized.

Copy link
Contributor

dougrk commented Dec 27, 2018

I thought about ways to pass the status message to the response without initializing/attaching a dictionary to every instance of HttpResponse. Creating a static variable is more difficult in VBA than I expected.

I have extracted the lookup to a new module, and included every HTTP Status Code, including 418 ;)

There are 2 iterations of public static lookup included among these commits. The older one uses a function that uses many ElseIfs, because of the difficulty of making a dictionary global. I personally don't consider this a maintenance issue as much as a file size issue. The living HTTP standard doesn't change that frequently.

Regardless, I did pursue an option that uses a dictionary. It is declared public in the module, and requires an initializer sub which is called from the main method. I made it so the sub isn't visible in the list of macros. Obviously the benefit over the other function solution is that key-value pairs can be iterated if needed. Although I feel like I have put a blemish on the application's very short main method. I don't know best practices for VBA, but my experience with other languages tells me this is an appropriate place to use a global dictionary.

@michaelneu

This comment has been minimized.

Copy link
Owner

michaelneu commented Jan 8, 2019

Sorry for the delay, looks good to me!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment