add: OPTIONS method support
add: relay tag endpoint
This commit is contained in:
		
							parent
							
								
									dab106c1f6
								
							
						
					
					
						commit
						420bdeb2aa
					
				
					 6 changed files with 158 additions and 26 deletions
				
			
		| 
						 | 
				
			
			@ -1,3 +1,4 @@
 | 
			
		|||
#include <constants.h>
 | 
			
		||||
#include <mongoose.h>
 | 
			
		||||
#include <logger.h>
 | 
			
		||||
#include <router.h>
 | 
			
		||||
| 
						 | 
				
			
			@ -13,7 +14,7 @@ handler_connection(struct mg_connection *c, int ev, void *p)
 | 
			
		|||
 | 
			
		||||
        endpoint_t *endpoint = router_find_endpoint(hm->uri.p, hm->uri.len, &hm->method);
 | 
			
		||||
 | 
			
		||||
        if(endpoint && endpoint->func)
 | 
			
		||||
        if(endpoint)
 | 
			
		||||
        {
 | 
			
		||||
            if(endpoint->func)
 | 
			
		||||
            {
 | 
			
		||||
| 
						 | 
				
			
			@ -29,7 +30,21 @@ handler_connection(struct mg_connection *c, int ev, void *p)
 | 
			
		|||
            }
 | 
			
		||||
            else
 | 
			
		||||
            {
 | 
			
		||||
                mg_send_head(c, 501, 0, "Content-Type: text/plain");
 | 
			
		||||
                if(endpoint->method == HTTP_METHOD_OPTIONS)
 | 
			
		||||
                {
 | 
			
		||||
                    char options_header[256]; // TODO make more generic
 | 
			
		||||
                    sprintf(options_header, "Allow: OPTIONS%s%s%s%s\r\n" STANDARD_HEADERS,
 | 
			
		||||
                            endpoint->options & HTTP_METHOD_GET ? ", GET" : "",
 | 
			
		||||
                            endpoint->options & HTTP_METHOD_POST ? ", POST" : "",
 | 
			
		||||
                            endpoint->options & HTTP_METHOD_PUT ? ", PUT" : "",
 | 
			
		||||
                            endpoint->options & HTTP_METHOD_DELETE ? ", DELETE" : ""
 | 
			
		||||
                    );
 | 
			
		||||
                    mg_send_head(c, 204, 0, options_header);
 | 
			
		||||
                }
 | 
			
		||||
                else
 | 
			
		||||
                {
 | 
			
		||||
                    mg_send_head(c, 501, 0, "Content-Type: text/plain");
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        else
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue