eclipse-archived / californium.core

Californium project
86 stars 69 forks source link

Use destination in getURI, if host is missing. #41

Closed boaks closed 9 years ago

boaks commented 9 years ago

Fixes bugs.eclipse.org #475816

Note: this implementation would return "localhost" even when using the loopback address as literal (e.g. "127.0.0.1").

Signed-off-by: Achim Kraus achim.kraus@bosch-si.com

mkovatsc commented 9 years ago

The problem with this is that getDestination() returns an InetAddress, which has this annoying notation with the slash (e.g., "/127.0.0.1") when the hostname was not resolved (which is usually the case).

boaks commented 9 years ago

Should I add a check for a "/" at the begin and skip it?

With the old implementation I was irritated always getting a "localhost" even if I use a different ip literal.

mkovatsc commented 9 years ago

We could simply store the value of URI.getHost() in setURI(). Originally, this was always done in the Uri-Host option. However, at some point this got "optimized away," since literals do not make sense in the option.

For now, we can do a quick fix with taking the string after the slash, which however, also needs a check for IPv6 to add the brackets.

In the long run, we need to re-design the URI handling (see http://dev.eclipse.org/mhonarc/lists/cf-dev/msg00309.html)

Originally, the host member was set to the authority part of the given URI and should be whatever was given by the user (either hostname or IP literal). Only if only a path is given, Cf assumed a local resource is addressed, so that "localhost" was inserted.

boaks commented 9 years ago

OK, I understand that my pull request is no solution; it just fixes my "special test setup" with literal IP. So, is it OK, if I close it (without being merged)?

mkovatsc commented 9 years ago

Sure, I am closing this now. However, I keep this as a bug to prepare a clean fix together with the URI handling.