Skip to content
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

registering content-length different than the actual body should have 2 different behaviours #1

Closed
gabrielfalcao opened this issue Feb 8, 2011 · 3 comments

Comments

@gabrielfalcao
Copy link
Owner

The first behaviour is:

import HTTPretty
HTTPretty.register_uri(HTTPretty.GET, "http://github.com/gabrielfalcao",
                       body="this is supposed to be the response",
                       adding_headers={
                           'Server': 'Apache',
                           'Content-Length': '23456789',
                           'Content-Type': 'application/json',
                       })

The expected content-length is 23456789 but the actual expected body has len 35

The DEFAULT behaviour is to raise an exception that says:

HTTPretty got inconsistent parameters. The header content-length expects size `23456789` 
but the body you registered for that has length `35`
Fix that, or if you really want that, call register_uri with "fill_with" callback. See the documentation for more.

Then the person can set the kwarg fill_with=lambda filedescriptor: "foobar", for example.
Or even use builtin callbacks such as:

import HTTPretty
HTTPretty.register_uri(HTTPretty.GET, "http://github.com/gabrielfalcao",
                       body="this is supposed to be the response",
                       fill_with=HTTPretty.zeros,
                       adding_headers={
                           'Server': 'Apache',
                           'Content-Length': '23456789',
                           'Content-Type': 'application/json',
                       })
@gabrielfalcao
Copy link
Owner Author

raising exception when the developer register a content-length bigger than actual body size. closed by a796971

@gabrielfalcao
Copy link
Owner Author

Oops, I missed to implement the callback :)

@gabrielfalcao
Copy link
Owner Author

The callback doesn't make sense since the developer can actually specify the body and the content-length

gabrielfalcao added a commit that referenced this issue Nov 11, 2012
pjsg referenced this issue in pjsg/HTTPretty Sep 24, 2019
Make sure that an initial // in the URL does not hurt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant