Closed MindPatch closed 3 years ago
Kinda like requests.request("GET","http://google.com")
?,
whats the benefit over just requests.get("http://google.com/")
?.
hi @juancarlospaco
we need functions like this in some cases, for example, i made a simple tool for take the method from the user and send http request to the url with the given method , so i'll create a function for take the method allowed and pass it to requests.request
function
import requests
def sender(method,url):
r = requests.request(method,url)
and this allows the user to send HTTP request with any method like CURL with -X
option
easy right, but if this function is not available in requests module the code will be like this
def sender(method,url):
method = method.upper()
if method == 'GET':
requests.get(url)
elif method == 'POST':
requests.post(url)
elif method == 'PUT':
requests.put(url)
--- ETC --
also, another function called requests.Request
do the same work of requests.request
but with empty headers (just Host
header)
I hope I explained it clearly
import requests def sender(method,url): r = requests.request(method,url)
But this would crash if user sends empty string as the method. Or any other value thats not an http method, so it is worse.
def sender(method,url): method = method.upper() if method == 'GET': requests.get(url) elif method == 'POST': requests.post(url) elif method == 'PUT': requests.put(url)
That code is better, because it can catch empty string or string that is not an http method.
To make it even better you should not use string for the method, but use an Enum
instead,
so it is impossible for the value to be empty string nor anything that is not an http method.
You can use empty headers.
I do not think this improves the API, because it makes it worse and more error-prone. You should use Enum instead of strings.
this is an example code of course if this is in a real app I'll add a check for an empty value
ok if I use the usual function in requests (get / put /post /etc..
), what about XPOST/XPUT methods how can I send requests with those methods?
my main question is not about the user but about the developers now I need to make an automation tool by nim for testing HTTP request smuggling, but this bug needs XPOST!
For GET
use get()
, for POST
use post()
, for PUT
use put()
.
This is a lib, not a executable program. If you need to do "manual" HTTP maybe use something like httpie or Insomnia https://insomnia.rest
hello, for short
requests
module python has a function calledrequest
with this you can send HTTP requests with any method for example :can you add something like that to your project?
best regards