0

This question is about the application's architecture and is thus language independent. Should it matter: I'm using python 3.6 and http.server.

Context and architecture

I'm writing a software that downloads some items from an online provider. The application will run locally but the design will be done with html so I'm designing it as a web application on localhost.

There are several kinds of item, so I have a plugin directory. Each plugin knows how to download a specific kind of item along with the varying meta-data. When the application loads, it instantiates every plugin. Then the server receives http requests and I have a simple for-loop that will forward the request to every plugins. By convention, only one plugin will then take control of the server to answer the request.

Here's the flow

  1. client sends http request
  2. server parses the request's endpoint and forwards to every plugins
  3. one plugin will recognize the endpoint and process the request
  4. plugins sends back an http response to server
  5. server forwards http response to client

Note: the plugin actually takes control of the server instance to answer. So there's coupling here. I'm happy with it because plugin depends on server instance but server does not depend on specific plugin instance.

Problem

I have a proxy plugin that must process a request and then forward it to another plugin. The problem is that the request data is passed as POST data and there is no way in http to forward post. The forward should require no action from the client.

I can either:

[1] Try and trick the client to resend the request with a javascript response. The flow will transit through the client:

client -> server -> proxy -> client (js) -> server -> plugin2

[2] Send a POST request programmatically directly from the plugin. The flow will transit through the server only:

client -> server -> proxy -> server -> plugin2

[3] Call the other plugin's code programmatically. The flow will transit directly between the two plugins

client -> server -> proxy -> plugin2

The first two options seems hacky and the third will introduce coupling between the two plugins, which seems like a bad idea (say the second plugin's code API changes, etc.)

What's the common solution to this kind of situation? What have you done in similar situation?

  • 1
    Does the proxy plugin change the request in any way, or does it just provide an alternative endpoint for some other plugin? If you want that the same request is just sent to another URI, you could return a status 307 and the new URI from the proxy plugin. – Bart van Ingen Schenau Jun 18 '18 at 12:18
  • @BartvanIngenSchenau Yes the data is edited – Julien__ Jun 18 '18 at 13:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.