hap icon indicating copy to clipboard operation
hap copied to clipboard

dnssd Name Conflict Resolution results in HTTP Bad Request

Open geekman opened this issue 1 year ago • 0 comments

Actually I'm not sure if I should file this in dnssd or hap, but I think the issue is unique to hap, so it's filed here.

When dnssd detects that a hostname is in use, it then tries to pick a different name by appending a space & number "%s %d", which is probably what iOS does too:

https://github.com/brutella/dnssd/blob/8574d113aa9e847409d25d90ac0ba1e0512f601c/probe.go#L76-L86

In doing so, the hostname now contains a space and HomeKit encodes the space as \032 in the Host: header which results in an invalid hostname under HTTP, so the http parser replies with an error. Related issue #9.

There's already an attempt to avoid spaces by replacing the server/accessory name before passing it to dnssd, but in this case the spaces were added by dnssd:

https://github.com/brutella/hap/blob/1a3e48cc763124df6ef3a958d0060415ce459a13/server.go#L509-L519

I'm not sure that iOS will fix this issue anytime soon (or at all), so maybe hap/dnssd should try to avoid generating such names. Maybe dnssd could defer to the caller (hap, in this case) for conflict resolution strategies, where it could send back "-" + random_hex_str instead of using " %d".

geekman avatar Dec 12 '23 09:12 geekman