mod_http_upload: Handle HEAD and OPTIONS requests
This commit is contained in:
		
							parent
							
								
									645d29a264
								
							
						
					
					
						commit
						6ca6f021cc
					
				@ -157,7 +157,7 @@ The configurable mod_http_upload options are:
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    custom_headers:
 | 
					    custom_headers:
 | 
				
			||||||
      "Access-Control-Allow-Origin": "*"
 | 
					      "Access-Control-Allow-Origin": "*"
 | 
				
			||||||
      "Access-Control-Allow-Methods": "GET, PUT"
 | 
					      "Access-Control-Allow-Methods": "OPTIONS, HEAD, GET, PUT"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
- rm_on_unregister (default: 'true')
 | 
					- rm_on_unregister (default: 'true')
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -363,7 +363,9 @@ process(LocalPath, #request{method = 'PUT', host = Host, ip = IP,
 | 
				
			|||||||
		     [?ADDR_TO_STR(IP), Host, Error]),
 | 
							     [?ADDR_TO_STR(IP), Host, Error]),
 | 
				
			||||||
	  http_response(Host, 500)
 | 
						  http_response(Host, 500)
 | 
				
			||||||
    end;
 | 
					    end;
 | 
				
			||||||
process(LocalPath, #request{method = 'GET', host = Host, ip = IP}) ->
 | 
					process(LocalPath, #request{method = Method, host = Host, ip = IP})
 | 
				
			||||||
 | 
					    when Method == 'GET';
 | 
				
			||||||
 | 
						 Method == 'HEAD' ->
 | 
				
			||||||
    Proc = gen_mod:get_module_proc(Host, ?PROCNAME),
 | 
					    Proc = gen_mod:get_module_proc(Host, ?PROCNAME),
 | 
				
			||||||
    case catch gen_server:call(Proc, get_docroot) of
 | 
					    case catch gen_server:call(Proc, get_docroot) of
 | 
				
			||||||
      {ok, DocRoot} ->
 | 
					      {ok, DocRoot} ->
 | 
				
			||||||
@ -401,14 +403,18 @@ process(LocalPath, #request{method = 'GET', host = Host, ip = IP}) ->
 | 
				
			|||||||
		http_response(Host, 500)
 | 
							http_response(Host, 500)
 | 
				
			||||||
	  end;
 | 
						  end;
 | 
				
			||||||
      Error ->
 | 
					      Error ->
 | 
				
			||||||
	  ?ERROR_MSG("Cannot handle GET request from ~s for ~s: ~p",
 | 
						  ?ERROR_MSG("Cannot handle ~s request from ~s for ~s: ~p",
 | 
				
			||||||
		     [?ADDR_TO_STR(IP), Host, Error]),
 | 
							     [Method, ?ADDR_TO_STR(IP), Host, Error]),
 | 
				
			||||||
	  http_response(Host, 500)
 | 
						  http_response(Host, 500)
 | 
				
			||||||
    end;
 | 
					    end;
 | 
				
			||||||
 | 
					process(_LocalPath, #request{method = 'OPTIONS', host = Host, ip = IP}) ->
 | 
				
			||||||
 | 
					    ?DEBUG("Responding to OPTIONS request from ~s for ~s",
 | 
				
			||||||
 | 
						   [?ADDR_TO_STR(IP), Host]),
 | 
				
			||||||
 | 
					    http_response(Host, 200);
 | 
				
			||||||
process(_LocalPath, #request{method = Method, host = Host, ip = IP}) ->
 | 
					process(_LocalPath, #request{method = Method, host = Host, ip = IP}) ->
 | 
				
			||||||
    ?DEBUG("Rejecting ~s request from ~s for ~s",
 | 
					    ?DEBUG("Rejecting ~s request from ~s for ~s",
 | 
				
			||||||
	   [Method, ?ADDR_TO_STR(IP), Host]),
 | 
						   [Method, ?ADDR_TO_STR(IP), Host]),
 | 
				
			||||||
    http_response(Host, 405, [{<<"Allow">>, <<"GET, PUT">>}]).
 | 
					    http_response(Host, 405, [{<<"Allow">>, <<"OPTIONS, HEAD, GET, PUT">>}]).
 | 
				
			||||||
 | 
					
 | 
				
			||||||
%%--------------------------------------------------------------------
 | 
					%%--------------------------------------------------------------------
 | 
				
			||||||
%% Internal functions.
 | 
					%% Internal functions.
 | 
				
			||||||
@ -732,7 +738,8 @@ code_to_message(403) -> <<"Forbidden.">>;
 | 
				
			|||||||
code_to_message(404) -> <<"Not found.">>;
 | 
					code_to_message(404) -> <<"Not found.">>;
 | 
				
			||||||
code_to_message(405) -> <<"Method not allowed.">>;
 | 
					code_to_message(405) -> <<"Method not allowed.">>;
 | 
				
			||||||
code_to_message(413) -> <<"File size doesn't match requested size.">>;
 | 
					code_to_message(413) -> <<"File size doesn't match requested size.">>;
 | 
				
			||||||
code_to_message(500) -> <<"Internal server error.">>.
 | 
					code_to_message(500) -> <<"Internal server error.">>;
 | 
				
			||||||
 | 
					code_to_message(_Code) -> <<"">>.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
%% Miscellaneous helpers.
 | 
					%% Miscellaneous helpers.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user