ofxHTTP icon indicating copy to clipboard operation
ofxHTTP copied to clipboard

Possible to have multiple post handler and generated pages?

Open DeqingSun opened this issue 8 years ago • 3 comments

Hi,

Is it possible to have multiple post handler with this library? Also I'd like show whether the file is acceptable. Can I have a dynamically generated upload.html?

Thanks

DeqingSun avatar May 12 '16 23:05 DeqingSun

Hi there, can you explain what you mean by multiple post handler?

If you mean having multiple post endpoints, yes you can add multiple post route handlers, just make sure they have different route path patterns (the default is /post). You can change it here:

https://github.com/bakercp/ofxHTTP/blob/2c1e3990e770fac9f33bdf0405a674e899b09558/libs/ofxHTTP/include/ofx/HTTP/PostRoute.h#L52-L54

Also, you can set valid content types in the PostRouteSettings .. e.g.

https://github.com/bakercp/ofxHTTP/blob/2c1e3990e770fac9f33bdf0405a674e899b09558/libs/ofxHTTP/include/ofx/HTTP/BaseRoute.h#L115-L120

If the upload content type is not included, it will be rejected.

You can also set the upload redirect page here:

https://github.com/bakercp/ofxHTTP/blob/2c1e3990e770fac9f33bdf0405a674e899b09558/libs/ofxHTTP/include/ofx/HTTP/PostRoute.h#L62

I'm not sure of the best return an "upload rejected" style message at the moment ... I think if you set a media type and the upload is incorrect, that will get you close ... but if you want to actually analyze the binary data using ofxLibmagic or something, that may need to be added as a feature.

bakercp avatar May 13 '16 00:05 bakercp

Thanks for your reply, Yes I'd like to have multiple post endpoints and I'm writing my own version of SimplePostServer.

Is it possible to print in a web response? Like I have a variable and I can see it's value on a web page?

DeqingSun avatar May 13 '16 00:05 DeqingSun

I'm also looking for an example to have multiple endpoints with their own handler.

It's clear you can change the endpoint for one particular PostRouteSettings, but how can we add multiple endpoints, each with their own handler, but running inside the same HTTP server?

https://github.com/bakercp/ofxHTTP/blob/master/example_basic_server_post/src/ofApp.cpp#L17-L36

There seems to be an addRoute method for the SimplePostServer class, but an example for setting multiple routes with their own handlers would be helpful. https://bakercp.github.io/ofxHTTP/classofx_1_1_h_t_t_p_1_1_simple_post_server.html

turiphro avatar Nov 12 '18 20:11 turiphro