NanoHttpd / nanohttpd

Tiny, easily embeddable HTTP server in Java.
http://nanohttpd.org
BSD 3-Clause "New" or "Revised" License
6.89k stars 1.69k forks source link

Can't set response status #616

Closed drandrewthomas closed 2 years ago

drandrewthomas commented 2 years ago

Hi,

I'm using nanohttpd in an android project, currently using aide. I import it as a dependency in the app build.gradle:

dependencies { implementation 'org.nanohttpd:nanohttpd:2.3.1' }

I can serve text responses no problem, but if I use a response that requires me to provide a status (in this case, an input stream response to serve files in the assets folder) I always get an error about the response (fixed length and chunked) needing an istatus. So, for example, if I try this code:

Response resp; resp=newFixedLengthResponse(""); resp.setMimeType(mime); resp.setData(mbuffer); resp.setStatus(Response.Status.OK);

then I get this error:

Method 'fi.iki.elonen.NanoHTTPD.Response.setStatus(fi.iki.elonen.NanoHTTPD.Response.IStatus)' can not be applied to 'fi.iki.elonen.NanoHTTPD.Response.setStatus(fi.iki.elonen.NanoHTTPD.Response.Status)'

I've tried creating an IStatus variable and setting it to Response.Status.OK, but then I get an error because it doesn't like me setting an IStatus to a Status value. Also, the same problem happens if I do something like this instead:

resp=newFixedLengthResponse(Response.Status.OK,mime,mbuffer);

I'm completely lost on what the problem is, so any help would be very welcome.

Thanks,

Andrew.

drandrewthomas commented 2 years ago

Hi again,

I decided to create a completely new project in the latest version of Android Studio, transferring the code into it as a clean new base for the project. The error I described above for AIDE running on Android didn't then happen in Android Studio on my Windows PC :-)

I don't know why this should happen in AIDE, but as it is probably an issue with older versions of gradle in AIDE projects it probably isn't an issue with NanoHTTPD. Therefore, I'll close this issue and hopefully anyone else having problems with NanoHTTPD in AIDE will find it for reference.

Many thanks,

Andrew.