[sheepdog] [PATCH 4/4] http: simplify http_run_request
MORITA Kazutaka
morita.kazutaka at gmail.com
Thu Nov 14 19:56:05 CET 2013
At Thu, 14 Nov 2013 17:03:54 +0800,
Liu Yuan wrote:
>
> Signed-off-by: Liu Yuan <namei.unix at gmail.com>
> ---
> sheep/http/http.c | 22 ++++++----------------
> 1 file changed, 6 insertions(+), 16 deletions(-)
>
> diff --git a/sheep/http/http.c b/sheep/http/http.c
> index 644cdc5..e9afedc 100644
> --- a/sheep/http/http.c
> +++ b/sheep/http/http.c
> @@ -209,37 +209,27 @@ static void http_run_request(struct work *work)
> struct http_driver *hdrv;
>
> list_for_each_entry(hdrv, &http_enabled_drivers, list) {
> - void (*method)(struct http_request *req) = NULL;
> -
> switch (op) {
> case HTTP_HEAD:
> - method = hdrv->head;
> + hdrv->head(req);
> break;
> case HTTP_GET:
> - method = hdrv->get;
> + hdrv->get(req);
> break;
> case HTTP_PUT:
> - method = hdrv->put;
> + hdrv->put(req);
> break;
> case HTTP_POST:
> - method = hdrv->post;
> + hdrv->post(req);
> break;
> case HTTP_DELETE:
> - method = hdrv->delete;
> + hdrv->delete(req);
> break;
> default:
> + http_response_header(req, METHOD_NOT_ALLOWED);
> break;
> }
> -
> - if (method != NULL) {
> - method(req);
> - if (req->status != UNKNOWN)
> - goto out;
> - }
> }
> -
> - http_response_header(req, METHOD_NOT_ALLOWED);
> -out:
> http_end_request(req);
> }
With this change, we have to implement all the http methods for each
http drivers, but I think it's not a good idea. If we add another
http_opcode in future, we have to update all the http drivers.
Moreover, I'm planning to add other drivers which will work on top of
s3 and swift API, and I think some of those drivers don't need to
handle all the http methods.
Thanks,
Kazutaka
More information about the sheepdog
mailing list