paste icon indicating copy to clipboard operation
paste copied to clipboard

Get path at process_request

Open gokh4n opened this issue 5 years ago • 2 comments

Hello, Firstly, the code worked very well, thank you for that. I have some problems. I'd appreciate it if you could help.

1. Problem - I want to get path at the process_request. Define two separate thread pools and i want to add requests to the thread pool by paths. I can get path, but the request is terminated. My sample code is below.

def __init__(self, nworkers, daemon=False, **threadpool_options):
    self.running = True
    assert nworkers > 0, "ThreadPoolMixIn servers must have at least one worker"
    self.thread_pool = ThreadPool(
        nworkers,
        "ThreadPoolMixIn HTTP server on %s:%d"
        % (self.server_name, self.server_port),
        daemon,
        **threadpool_options)

def process_request(self, request, client_address):
    request.setblocking(1)
    path = str(request.makefile('rb', -1).readline(65537), 'iso-8859-1').rstrip('\r\n').split()[1]
    self.thread_pool.add_task(
         lambda: self.process_request_in_thread(request, client_address))

2. Problem - I want to set different timeout value of request by paths.

Thanks

gokh4n avatar Aug 03 '19 09:08 gokh4n

I'm having a little trouble trying to understand what you are trying to do, but if you are trying to get the URL of the request the request.script_name and request.path_info may help, assuming that request is a WSGIRequest object from paste.wsgiwrappers.

If you're able to explain more about what are you trying to do, I may be able to provide more information but also keep in mind the warning from the top of the readme: "please consider using other options".

cdent avatar Aug 03 '19 11:08 cdent

Thanks you for your answer. I can try to get request.path_info in process_request function. Because i have two thread pools. I want to add task in thread pool by request path. But i cant do it.

gokh4n avatar Aug 04 '19 10:08 gokh4n