From 1cafc3eff956f9753777e85677e2cbd728650fef Mon Sep 17 00:00:00 2001 From: bill-auger Date: Mar 10 2019 03:39:49 +0000 Subject: distinguish GET|POST --- diff --git a/forge-fed.wsgi b/forge-fed.wsgi index 50cb61d..c5f21e7 100644 --- a/forge-fed.wsgi +++ b/forge-fed.wsgi @@ -9,19 +9,31 @@ from activitypub.manager import Manager from activitypub.database import ListDatabase -def inbox_handler(env): return [ '200 OK' , "inbox" ] -def followers_handler(env): return [ '200 OK' , "followers" ] -def following_handler(env): return [ '200 OK' , "following" ] -def liked_handler(env): return [ '200 OK' , "liked" ] -def likes_handler(env): return [ '200 OK' , "likes" ] -def outbox_handler(env): return [ '200 OK' , "outbox" ] +def inbox_get_handler(env): return [ '200 OK' , "GET/inbox" ] +def followers_get_handler(env): return [ '200 OK' , "GET/followers" ] +def following_get_handler(env): return [ '200 OK' , "GET/following" ] +def liked_get_handler(env): return [ '200 OK' , "GET/liked" ] +def likes_get_handler(env): return [ '200 OK' , "GET/likes" ] +def outbox_get_handler(env): return [ '200 OK' , "GET/outbox" ] +def inbox_post_handler(env): return [ '200 OK' , "POST/inbox" ] +def followers_post_handler(env): return [ '200 OK' , "POST/followers" ] +def following_post_handler(env): return [ '200 OK' , "POST/following" ] +def liked_post_handler(env): return [ '200 OK' , "POST/liked" ] +def likes_post_handler(env): return [ '200 OK' , "POST/likes" ] +def outbox_post_handler(env): return [ '200 OK' , "POST/outbox" ] ROUTES = { - '/inbox' : inbox_handler , - '/followers' : followers_handler , - '/following' : following_handler , - '/liked' : liked_handler , - '/likes' : likes_handler , - '/outbox' : outbox_handler + 'GET/inbox' : inbox_get_handler , + 'GET/followers' : followers_get_handler , + 'GET/following' : following_get_handler , + 'GET/liked' : liked_get_handler , + 'GET/likes' : likes_get_handler , + 'GET/outbox' : outbox_get_handler , + 'POST/inbox' : inbox_post_handler , + 'POST/followers' : followers_post_handler , + 'POST/following' : following_post_handler , + 'POST/liked' : liked_post_handler , + 'POST/likes' : likes_post_handler , + 'POST/outbox' : outbox_post_handler } @@ -39,8 +51,9 @@ def application(env , start_response): path = env.get('PATH_INFO').replace('/forge-fed/' , '/') method = env.get('REQUEST_METHOD') query = env.get('QUERY_STRING') - route_fn = ROUTES.get(path) - resp = route_fn(env) if path in ROUTES else [ '404 NOT FOUND' , '_4_0_4_' ] + routes_key = method + path + route_fn = ROUTES.get(routes_key) + resp = route_fn(env) if routes_key in ROUTES else [ '404 NOT FOUND' , '_4_0_4_' ] status = resp[0] body = resp[1] content_type = 'text/plain' @@ -50,11 +63,12 @@ def application(env , start_response): # DEBUG BEGIN - print('path = ' + path + '\n' + \ - 'method = ' + method + '\n' + \ - 'query = ' + query + '\n' + \ - 'status = ' + status + '\n' + \ - 'body = ' + body + '\n' ) + print('path = ' + path + '\n' + \ + 'method = ' + method + '\n' + \ + 'query = ' + query + '\n' + \ + 'route_fn = ' + str(route_fn) + '\n' + \ + 'status = ' + status + '\n' + \ + 'body = ' + body + '\n' ) # DEBUG END