hwebserver: how to redirect POST request?

   969   2   1
User Avatar
Member
30 posts
Joined: Nov. 2010
Offline
Hi,

So using hwebserver I cannot figure out how to redirect a request, so that's received as POST.

What I'm talking is a situation like this:

    # Sending from a server on port 5001    
    @hwebserver.urlHandler(url, is_prefix=True)
    def handler(request):
        return hwebserver.redirect(request, f'{localhost}:5002/')

    
    # Receiving server is on port 5002 
    @hwebserver.urlHandler(url, is_prefix=True)
    def handler(request):
        # The request method is always GET
        print(f'{request.method()}')
        return hwebserver.Response('')

The request received on the server running on the port 5002 is always a GET request. Unless I directly send a POST request.
Can I somehow configure the
hwebserver.redirect(request)
so it will be received as a POST on the other server?
User Avatar
Staff
178 posts
Joined: Oct. 2018
Offline
Hi, I'm not sure that I understand the setup. Why do you need two ports for the server? You can listen on one port and serve both GET and POST requests on the same port (and on the same path). Your client code should know if the request is a GET or POST but if for some reason the client doesn't then the server can always return a 404 response and the client sends the other request.

Cheers,
Matt Warner
Software Developer - Licensing
SideFX
User Avatar
Member
30 posts
Joined: Nov. 2010
Offline
Hi Matt,

That's because I'm trying to implement something like microservices. One server that people communicate to, which decides what needs to be done, redirects to a proper server that runs the task. So I have at least two separate hython processes.

The manager server receives a POST request from the client. The manager decides this job has to be nadled by the worker server, so it redirects to a different server (which can be the same machine, but doesn't have to). But once the request is received by a worker server, the request.method() is GET.

I can work with GET, but then the manager server has to besically take everything in request.body(), convert to a query string. Because the worker needs instructions on what to do. And depends on how much data is in the request.body() I might run out of characters in the url (I think the limit is 2048).

Redirecting the request, so it's a POST on another server, would be just less complicated for development.
  • Quick Links