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

HttpListener now listens on default ports if not specified instead of random #891

Merged
merged 1 commit into from
Feb 17, 2014

Conversation

DavidKarlas
Copy link
Member

In method public static void CheckUri I just made code a bit nicer.

In method Parse I fixed bug where default_port variable was set but never used in case if URI did not have port specified. Since port was set by default 0 HttpListener would listen on random port instead 80 or 443. Also notice that this class is private and only used by Mono so CheckUri is always called before Parse() which means only "http://" and "https://" schemas are possible so I changed beginning of Parse method a bit. "optimization" :)

This is also behaviour of .Net(no port specified results in port 80 on http schema).

I ran into this problem using Nancy because there self hosting accepts Uri objects which is later sent to HttpListener prefixes by using .ToString() which omits port number(see Uri.cs).

Seems like some other guys ran into same problem here: http://stackoverflow.com/questions/19741880/nancy-mono-self-host-wont-start-on-port-80

DavidKarlas added a commit to DavidKarlas/Nancy that referenced this pull request Feb 8, 2014
This is more like suggestion then actual pull request since I'm not 100% that baseUri.AbsolutePath is covering all scenarios... One other option could be baseUri.OriginalString(breaking change?)

For more info about Mono bug see mono/mono#891 and http://stackoverflow.com/questions/19741880/nancy-mono-self-host-wont-start-on-port-80.

Basically problem is that with ToString() ports 80 and 443 are removed and Mono's HttpListener has bug that does not listen on default port if port is not specified but random. This workaround is to be able to work on older versions of Mono because apt-get mono is updating really slow and will take probably year to get into apt-get...

As you wish ;)
@marek-safar
Copy link
Member

Could you write unit test for the change

@DavidKarlas
Copy link
Member Author

Should I write unit tests for mcs/class/System/System.Net/ListenerPrefix.cs and send different strings in and see if Properties(Secure, Host, Port, Path) are correct or mcs/class/System/System.Net/HttpListener.cs were port will actually be opened? Notice that if actually opening HttpListener.cs will require "sudo" because opening listener on port 80 requires sudo access.

@marek-safar
Copy link
Member

That's unit test. No need to check whether the port is actually open/working. It'd be enough to use the combination Nancy has and assert on ToString result

@DavidKarlas
Copy link
Member Author

Unfortunately mcs/class/System/System.Net/ListenerPrefix.cs is private class so only way to test it directly would be using reflection(I can do that if you want :))...
So I created test on HttpListener(testing blackbox instead of whitebox)
Notice that I check if test is possible to perform(no root access or port 80 already in use)... and ignore if not possible...

marek-safar added a commit that referenced this pull request Feb 17, 2014
HttpListener now listens on default ports if not specified instead of random
@marek-safar marek-safar merged commit 657b95a into mono:master Feb 17, 2014
@DavidKarlas DavidKarlas deleted the listenerprefix branch February 17, 2014 12:59
@bonesoul
Copy link

I guess this is included within mono 3.8 right?

@knocte
Copy link
Contributor

knocte commented Sep 22, 2014

Yes.

Red54 pushed a commit to Red54/mono that referenced this pull request Mar 15, 2019
…-typeof

Use typeof instead of Type.GetType for webconnection HttpsClientStream
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.

None yet

4 participants