NanoHttpd / nanohttpd

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

Custom handler #478

Closed arjunmenon closed 6 years ago

arjunmenon commented 6 years ago

Hey What is a simple example of handling a custom HTTP method? Frankly, there is not much how-to on this and I really want to know.

PS want to handle NOTIFY and SUBSCRIBE HTTP methods and return a 200 OK

pathikdevani commented 6 years ago

custom HTTP? can you provide a sample? @arjunmenon

Debjyotinath commented 6 years ago

I also have a similar request. What i basically want to understand, is there a way to handle custom http methods? Like in the above example @arjunmenon wants to define a Method.NOTIFY. The server should be able to understand the http method "NOTIFY" and accordingly handle the request. But in the current case and custom method, changes it to Method.OPTIONS. SO kindly help us to understand how to do it.

arjunmenon commented 6 years ago

I think its not possible in previous version which are in maven. Since they are locked in an enum. Wonder why though they have mentioned this in their feature list -

Some built-in support for HEAD, POST and DELETE requests. You can easily implement/customize any HTTP method, though.

The original version of Nanohttps simply checked for String - https://github.com/NanoHttpd/nanohttpd-java-1.1/blob/nanohttpd-for-java1.1/NanoHTTPD.java#L86

LordFokas commented 6 years ago

A PR was just approved with a quick and dirty addition to the Method enum. In a future version I plan to make this a truly extensible system.