bakercp / ofxHTTP

A suite of HTTP tools, including clients and servers for openFrameworks.
MIT License
110 stars 37 forks source link

Possible to have multiple post handler and generated pages? #40

Open DeqingSun opened 8 years ago

DeqingSun commented 8 years ago

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

bakercp commented 8 years ago

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.

DeqingSun commented 8 years ago

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?

turiphro commented 5 years ago

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