-
Notifications
You must be signed in to change notification settings - Fork 774
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to match an empty response body? #1629
Comments
I made a small debug Python server: from http.server import BaseHTTPRequestHandler, HTTPServer
class SimpleHTTPRequestHandler(BaseHTTPRequestHandler):
def do_GET(self):
if self.path == '/nothing':
self.send_response(200)
self.end_headers()
elif self.path == '/nothing_cl0':
self.send_response(200)
self.send_header('Content-Length', '0')
self.end_headers()
elif self.path == '/nothing_cl1':
self.send_response(200)
self.send_header('Content-Length', '1')
self.end_headers()
def run(server_class=HTTPServer, handler_class=SimpleHTTPRequestHandler, port=8000):
server_address = ('', port)
httpd = server_class(server_address, handler_class)
print(f'Starting httpd on port {port}...')
httpd.serve_forever()
if __name__ == '__main__':
run() And check it with (there will be some errors because httpx tries https first):
With Originally posted by @Yardanico in #1628 (comment) |
Discussed in #1628
Originally posted by Yardanico March 13, 2024
Hi, I've been using httpx for quite a long time, and it's a really great project! Right now I'm struggling a bit to match empty response bodies. It looks to me that there's no DSL variable that I can use to get the actual length of the response body?
As far as I understand,
content_length
just takesContent-Length
from response headers, and it's not defined if there's no such header present (I know that websites shouldn't respond like this, but sadly almost no one follows standards nowadays):So yeah, maybe I missed something obvious, but - how do I filter such websites? I've tried checking the hash -
body_md5
is also not present, but funnily enough httpx still gives out the hash (for an empty 0 byte string) in its output when asked:Both word and line count are 1 for a completely empty body, but they can also be 1 for legitimate short responses, so I can't use them to filter out completely empty responses.
The text was updated successfully, but these errors were encountered: