mirror of
				https://github.com/Mikaela/Limnoria.git
				synced 2025-10-31 15:47:25 +01:00 
			
		
		
		
	httpserver: Respond to HEAD requests. Closes GH-1203.
This commit is contained in:
		
							parent
							
								
									1d162dd048
								
							
						
					
					
						commit
						4576874128
					
				| @ -119,7 +119,7 @@ httpserver.set_default_templates(DEFAULT_TEMPLATES) | |||||||
| class FactoidsCallback(httpserver.SupyHTTPServerCallback): | class FactoidsCallback(httpserver.SupyHTTPServerCallback): | ||||||
|     name = 'Factoids web interface' |     name = 'Factoids web interface' | ||||||
| 
 | 
 | ||||||
|     def doGet(self, handler, path): |     def doGetOrHead(self, handler, path, write_content): | ||||||
|         parts = path.split('/')[1:] |         parts = path.split('/')[1:] | ||||||
|         if path == '/': |         if path == '/': | ||||||
|             self.send_response(200) |             self.send_response(200) | ||||||
| @ -132,6 +132,7 @@ class FactoidsCallback(httpserver.SupyHTTPServerCallback): | |||||||
|                 self.send_response(404) |                 self.send_response(404) | ||||||
|                 self.send_header('Content-type', 'text/html; charset=utf-8') |                 self.send_header('Content-type', 'text/html; charset=utf-8') | ||||||
|                 self.end_headers() |                 self.end_headers() | ||||||
|  |                 if write_content: | ||||||
|                     self.write(httpserver.get_template('generic/error.html')% |                     self.write(httpserver.get_template('generic/error.html')% | ||||||
|                         {'title': 'Factoids - not a channel', |                         {'title': 'Factoids - not a channel', | ||||||
|                          'error': 'This is not a channel'}) |                          'error': 'This is not a channel'}) | ||||||
| @ -140,6 +141,7 @@ class FactoidsCallback(httpserver.SupyHTTPServerCallback): | |||||||
|                 self.send_response(403) |                 self.send_response(403) | ||||||
|                 self.send_header('Content-type', 'text/html; charset=utf-8') |                 self.send_header('Content-type', 'text/html; charset=utf-8') | ||||||
|                 self.end_headers() |                 self.end_headers() | ||||||
|  |                 if write_content: | ||||||
|                     self.write(httpserver.get_template('generic/error.html')% |                     self.write(httpserver.get_template('generic/error.html')% | ||||||
|                         {'title': 'Factoids - unavailable', |                         {'title': 'Factoids - unavailable', | ||||||
|                          'error': 'This channel does not exist or its factoids ' |                          'error': 'This channel does not exist or its factoids ' | ||||||
| @ -173,6 +175,7 @@ class FactoidsCallback(httpserver.SupyHTTPServerCallback): | |||||||
|             self.send_response(200) |             self.send_response(200) | ||||||
|             self.send_header('Content-type', 'text/html; charset=utf-8') |             self.send_header('Content-type', 'text/html; charset=utf-8') | ||||||
|             self.end_headers() |             self.end_headers() | ||||||
|  |             if write_content: | ||||||
|                 self.write(httpserver.get_template('factoids/channel.html')% |                 self.write(httpserver.get_template('factoids/channel.html')% | ||||||
|                         {'channel': channel, 'rows': content}) |                         {'channel': channel, 'rows': content}) | ||||||
|     def doPost(self, handler, path, form): |     def doPost(self, handler, path, form): | ||||||
|  | |||||||
| @ -305,15 +305,21 @@ class SupyHTTPServerCallback(log.Firewalled): | |||||||
|         def write(self, s): |         def write(self, s): | ||||||
|             self.wfile.write(s) |             self.wfile.write(s) | ||||||
| 
 | 
 | ||||||
|     def doGet(self, handler, path, *args, **kwargs): |     def doGetOrHead(self, handler, path, write_content): | ||||||
|         response = self.defaultResponse.encode() |         response = self.defaultResponse.encode() | ||||||
|         handler.send_response(405) |         handler.send_response(405) | ||||||
|         self.send_header('Content-Type', 'text/plain; charset=utf-8; charset=utf-8') |         self.send_header('Content-Type', 'text/plain; charset=utf-8; charset=utf-8') | ||||||
|         self.send_header('Content-Length', len(response)) |         self.send_header('Content-Length', len(response)) | ||||||
|         self.end_headers() |         self.end_headers() | ||||||
|  |         if write_content: | ||||||
|             self.wfile.write(response) |             self.wfile.write(response) | ||||||
| 
 | 
 | ||||||
|     doPost = doHead = doGet |     def doGet(self, handler, path): | ||||||
|  |         self.doGetOrHead(handler, path, write_content=True) | ||||||
|  |     def doHead(self, handler, path): | ||||||
|  |         self.doGetOrHead(handler, path, write_content=False) | ||||||
|  | 
 | ||||||
|  |     doPost = doGet | ||||||
| 
 | 
 | ||||||
|     def doHook(self, handler, subdir): |     def doHook(self, handler, subdir): | ||||||
|         """Method called when hooking this callback.""" |         """Method called when hooking this callback.""" | ||||||
| @ -331,7 +337,7 @@ class Supy404(SupyHTTPServerCallback): | |||||||
|     if I don't know what to serve. |     if I don't know what to serve. | ||||||
|     What I'm saying is you just triggered a 404 Not Found, and I am not |     What I'm saying is you just triggered a 404 Not Found, and I am not | ||||||
|     trained to help you in such a case.""") |     trained to help you in such a case.""") | ||||||
|     def doGet(self, handler, path, *args, **kwargs): |     def doGetOrHead(self, handler, path, write_content): | ||||||
|         response = self.response |         response = self.response | ||||||
|         if minisix.PY3: |         if minisix.PY3: | ||||||
|             response = response.encode() |             response = response.encode() | ||||||
| @ -339,16 +345,15 @@ class Supy404(SupyHTTPServerCallback): | |||||||
|         self.send_header('Content-Type', 'text/plain; charset=utf-8; charset=utf-8') |         self.send_header('Content-Type', 'text/plain; charset=utf-8; charset=utf-8') | ||||||
|         self.send_header('Content-Length', len(self.response)) |         self.send_header('Content-Length', len(self.response)) | ||||||
|         self.end_headers() |         self.end_headers() | ||||||
|  |         if write_content: | ||||||
|             self.wfile.write(response) |             self.wfile.write(response) | ||||||
| 
 | 
 | ||||||
|     doPost = doHead = doGet |  | ||||||
| 
 |  | ||||||
| class SupyIndex(SupyHTTPServerCallback): | class SupyIndex(SupyHTTPServerCallback): | ||||||
|     """Displays the index of available plugins.""" |     """Displays the index of available plugins.""" | ||||||
|     name = "index" |     name = "index" | ||||||
|     fullpath = True |     fullpath = True | ||||||
|     defaultResponse = _("Request not handled.") |     defaultResponse = _("Request not handled.") | ||||||
|     def doGet(self, handler, path): |     def doGetOrHead(self, handler, path, write_content): | ||||||
|         plugins = [x for x in handler.server.callbacks.items()] |         plugins = [x for x in handler.server.callbacks.items()] | ||||||
|         if plugins == []: |         if plugins == []: | ||||||
|             plugins = _('No plugins available.') |             plugins = _('No plugins available.') | ||||||
| @ -362,6 +367,7 @@ class SupyIndex(SupyHTTPServerCallback): | |||||||
|         self.send_header('Content-Type', 'text/html; charset=utf-8') |         self.send_header('Content-Type', 'text/html; charset=utf-8') | ||||||
|         self.send_header('Content-Length', len(response)) |         self.send_header('Content-Length', len(response)) | ||||||
|         self.end_headers() |         self.end_headers() | ||||||
|  |         if write_content: | ||||||
|             self.wfile.write(response) |             self.wfile.write(response) | ||||||
| 
 | 
 | ||||||
| class Static(SupyHTTPServerCallback): | class Static(SupyHTTPServerCallback): | ||||||
| @ -372,7 +378,7 @@ class Static(SupyHTTPServerCallback): | |||||||
|     def __init__(self, mimetype='text/plain; charset=utf-8'): |     def __init__(self, mimetype='text/plain; charset=utf-8'): | ||||||
|         super(Static, self).__init__() |         super(Static, self).__init__() | ||||||
|         self._mimetype = mimetype |         self._mimetype = mimetype | ||||||
|     def doGet(self, handler, path): |     def doGetOrHead(self, handler, path, write_content): | ||||||
|         response = get_template(path) |         response = get_template(path) | ||||||
|         if minisix.PY3: |         if minisix.PY3: | ||||||
|             response = response.encode() |             response = response.encode() | ||||||
| @ -380,13 +386,14 @@ class Static(SupyHTTPServerCallback): | |||||||
|         self.send_header('Content-type', self._mimetype) |         self.send_header('Content-type', self._mimetype) | ||||||
|         self.send_header('Content-Length', len(response)) |         self.send_header('Content-Length', len(response)) | ||||||
|         self.end_headers() |         self.end_headers() | ||||||
|  |         if write_content: | ||||||
|             self.wfile.write(response) |             self.wfile.write(response) | ||||||
| 
 | 
 | ||||||
| class Favicon(SupyHTTPServerCallback): | class Favicon(SupyHTTPServerCallback): | ||||||
|     """Services the favicon.ico file to browsers.""" |     """Services the favicon.ico file to browsers.""" | ||||||
|     name = 'favicon' |     name = 'favicon' | ||||||
|     defaultResponse = _('Request not handled') |     defaultResponse = _('Request not handled') | ||||||
|     def doGet(self, handler, path): |     def doGetOrHead(self, handler, path, write_content): | ||||||
|         response = None |         response = None | ||||||
|         file_path = conf.supybot.servers.http.favicon() |         file_path = conf.supybot.servers.http.favicon() | ||||||
|         if file_path: |         if file_path: | ||||||
| @ -407,6 +414,7 @@ class Favicon(SupyHTTPServerCallback): | |||||||
|             # self.send_header('Content-Length', len(response)) |             # self.send_header('Content-Length', len(response)) | ||||||
|             # self.send_header('Content-type', 'image/' + ext) |             # self.send_header('Content-type', 'image/' + ext) | ||||||
|             # self.end_headers() |             # self.end_headers() | ||||||
|  |             if write_content: | ||||||
|                 self.wfile.write(response) |                 self.wfile.write(response) | ||||||
|         else: |         else: | ||||||
|             response = _('No favicon set.') |             response = _('No favicon set.') | ||||||
| @ -416,6 +424,7 @@ class Favicon(SupyHTTPServerCallback): | |||||||
|             self.send_header('Content-type', 'text/plain; charset=utf-8') |             self.send_header('Content-type', 'text/plain; charset=utf-8') | ||||||
|             self.send_header('Content-Length', len(response)) |             self.send_header('Content-Length', len(response)) | ||||||
|             self.end_headers() |             self.end_headers() | ||||||
|  |             if write_content: | ||||||
|                 self.wfile.write(response) |                 self.wfile.write(response) | ||||||
| 
 | 
 | ||||||
| http_servers = [] | http_servers = [] | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 Valentin Lorentz
						Valentin Lorentz