Skip to content

Commit

Permalink
Fix: fix bug in http
Browse files Browse the repository at this point in the history
  • Loading branch information
Lee-WonJun committed Jul 23, 2023
1 parent b7f7d5b commit 4d50c3d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
4 changes: 2 additions & 2 deletions ninja/http.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from .service.call_http import call_http
from .service.common import COMMON, STRING
from .service.http import call_http

CATEGORY = "NINJA/Http"

Expand All @@ -24,7 +24,7 @@ def INPUT_TYPES(s):
"method": (HTTP_METHODS,),
"server_url": (STRING, {
"multiline": False,
"default": "localhost:8000",
"default": "http:https://localhost:8000",
}),
"headers": (STRING, {
"multiline": True,
Expand Down
18 changes: 13 additions & 5 deletions ninja/service/http.py → ninja/service/call_http.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import requests

from ninja.service.common import with_debug_log
from .common import with_debug_log


def call_http(method, server_url, headers, body, params0, params1, params2, params3, params4, params5, params6,
params7, params8, params9):
import requests
params = {
"$$0": params0,
"$$1": params1,
Expand All @@ -17,12 +16,21 @@ def call_http(method, server_url, headers, body, params0, params1, params2, para
"$$8": params8,
"$$9": params9,
}

for k, v in params:
for k, v in params.items():
server_url = server_url.replace(k, v)
body = body.replace(k, v)
headers = headers.replace(k, v)

headers = dict([x.split(":") for x in headers.split(";") if x != ""])
headers = {k.strip(): v.strip() for k, v in headers.items()}
import json
try:
body = json.loads(body)
except:
body = json.loads("{" + body + "}")
print(headers)
print(body)

if method == "GET":
resp = requests.get(server_url, headers=headers)
elif method == "POST":
Expand Down

0 comments on commit 4d50c3d

Please sign in to comment.