Comments (1)
So, finally came back to this and think I figured out the problem. When binding to http://localhost
as a URL prefix, EndPointManager will only grab the first resolution from Dns.GetHostAddresses()
. On most systems, this will be the IPv6 loopback address of ::1
. The actual resolution for 127.0.0.1
goes completely ignored. The EmbedIO listener will then dutifully set up its listener on ::1
, as we expect.
Because, however, we are also registering to http://127.0.0.1
, EmbedIO binds to both the IPv4 and IPv6 interfaces. When running curl --ipv4 http://localhost:45454/
, we connect to the IPv4-only EndPointListener
which is not aware of the localhost
prefix:
As a result, the server steps through SearchListener
, fails to find an appropriate match, and BindContext
returns false
, killing the connection:
(Of note, while exploring this, I came across issue #165 which had a similar comment - binding to 0.0.0.0
actually creates something that listens on all interfaces, but because the EndPointListener
is not aware of 0.0.0.0
being "special", it also gives up. This is doubly made interesting by the fact that EndPointManager.cs#L96 actually has something in place for this edge case, allowing it to bind to [::]
instead, but I'm on a tangent so I'll get back to the issue at hand.)
As an experiment, I wrote a (very quick and dirty) patch that changed the behavior of GetEpListener
to instead return a list of eligible listeners (assuming more than one is returned by the aforementioned DNS query). This, to my surprise, actually seems to work:
The localhost
prefix is added to both the IPv4 and IPv6 listeners, and cURL can connect to either one and receive the expected response. In addition, the actual IP addresses also defined also can connect and get routed appropriately, bringing everything back to what I would have expected. I'm more than happy to formally submit this patch as a PR, but I'm unsure what else would be needed before then (and what other things are lurking in EndPointListener that should be looked at).
(Edit: The above patch diverges from Mono's behavior, which I suspect is not a desired change. Would it make sense to open this issue with the Mono team directly? As far as I can tell from Mono's code, they'd have the same problem - setting prefixes to 127.0.0.1
and [::1]
would work, but connects with Host: localhost
would be rejected. All this to say EmbedIO v4 can't come soon enough!)
As for why all this came up in the first place: browsers are problematic. Despite the fact that Windows is usually pretty consistent (ha) about returning DNS records for localhost
in the same order, browsers will sometimes decide that they want to swap things around or prefer IPv4 to IPv6 at times. This causes the browser to resolve localhost
to 127.0.0.1
and hit the EndPointListener
with no knowledge that it should be responding to localhost
, because all it knows is IPv6.
from embedio.
Related Issues (20)
- Cannot control charset in ContentType header HOT 3
- How to send statuscode 202 HOT 1
- EmbedIO 3.5.0 NuGet package references wrong/old version of Unosquare.Swan.Lite HOT 22
- System.ObjectDisposedException when processing multiple requests at once HOT 2
- WithZipFile should open a read only handle(or have the option to) HOT 2
- FileModule or StaticFolderModule get stuck returning medium files HOT 4
- Add XML as response type
- How can I custom the Server header HOT 2
- Disable request logging only
- Cookies issue
- EmbedIO.Samples console app does not work when PublishAot is set to true HOT 2
- Web Server does not work in Xamarin.iOS (IOS-17) HOT 3
- How to report progess via api - event-stream
- HttpContext.OnClose not firing HOT 1
- Getting rid of double quotes around strings in a Web API response (turning off JSON serialization) HOT 1
- Issue Serving Static Folder Xamarin ( 3.5.2) Forms on Android
- Request.Url mixing up http and https
- server stop responding after some time HOT 4
- The return array is empty. HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from embedio.