SteveyO / Hue-Emulator

A Bridge API Emulator for the Philips Hue (Personal Wireless System)
165 stars 41 forks source link

Unable to perform PUT from webapps #38

Closed josh-oakes closed 6 years ago

josh-oakes commented 6 years ago

I'm not able to perform any PUT requests against the emulator from a webapp that I am using (Swagger Editor to create API spec). GET requests all appear to be coming through ok so I thought it might have been a CORS issue but it looks like your UPnP server has Access-Control-Allow-Origin set to "*" so I think that should be good.

Is this something you have ever run into?

jpoppe commented 6 years ago

Same issue here, I suspect it has to do with Access-Control-Allow-Methods or Access-Control-Allow-Headers . Chrome uses OPTIONS instead of PUT*. Did not have enough time yet to inspect this further.

tcpdump Curl request:

PUT /api/newdeveloper/lights/3 HTTP/1.1
Host: 127.0.0.1:8000
User-Agent: curl/7.55.1
Accept: */*
Content-Length: 17
Content-Type: application/x-www-form-urlencoded

tcpdump Chrome request:

OPTIONS /api/newdeveloper/lights/3 HTTP/1.1
Host: localhost:8000
Connection: keep-alive
Access-Control-Request-Method: PUT
Origin: https://censored:1337
User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko)
Chrome/63.0.3223.8 Safari/537.36
Accept: */*
Accept-Encoding: gzip, deflate, br
Accept-Language: en-US,en;q=0.9,nl;q=0.8 

tcpdump command sudo tcpdump -i lo port 8000 -A -n

I tried this with XHR and fetch requests from Chrome.

rossmuego commented 6 years ago

I too am having this issue, did you come up with a solution? @jpoppe

SteveyO commented 6 years ago

Hi guys, As am sure you have probably noticed, I haven't been maintaining the emulator for a while sorry. It's not something I know a great deal about either (I have never tested from a web app, just from local applications). If anyone finds a solution, feel free to create a pull request and I will merge in master, and create a new version. There are a few open pull requests which I will address soon. Steve

mi-g commented 6 years ago

Hey SteveyO,

I just submitted a PR with a fix for this issue. This is a very simple change: one line of code to close the request if HTTP method is not GET/POST/PUT/DELETE (we want the emulator to process OPTIONS requests).

Could you review/merge the PR and push a 0.8 release ? This would be by far the best solution but if for any reason you cannot do so, since the licensing of your project is unclear, would you allow others to make the new jar for public access ? I need to make people without a real hue system able to test my application and your emulator is definitely the best one around, now that it is compatible with modern browsers.

Thanks, /mig

SteveyO commented 6 years ago

Hey mig,

Thanks for the PR. Actually there are a few open PRs from the past year which I haven't looked at yet. I will take a look at all of these during the week and create a new .jar over the weekend or earlier if I can with all recent fixes. Thanks for submitting the PR.

I will try and keep more up-to-date in the future. I have been a bit slack I know. Steve

mi-g commented 6 years ago

Many thanks for the update ! I think we can close this issue now.

SteveyO commented 6 years ago

Great! Thanks for letting me know. I will close the issue and if it re-occurs can re-open.