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

Return the raw HTTP response #71

Closed
wants to merge 1 commit into from
Closed

Return the raw HTTP response #71

wants to merge 1 commit into from

Conversation

alazaro
Copy link

@alazaro alazaro commented Sep 19, 2015

In some cases you don't need to get any of the elements of the JSON object, but the object itself. I couldn't find the way to do that so I introduced a very small modification to the MiniJsonExtractor. If no key is specified, the whole object will be returned.

@svanoort svanoort changed the title Return the same object if no key in MiniJsonExtractor Return the raw HTTP response Sep 23, 2015
@svanoort
Copy link
Owner

I see what you're doing here, and agree there's a use case. There's a better way to do this though: define a RawBodyExtractor. This way it works with any response (not necessarily just JSON), and it doesn't require unexpected behavior from the MiniJsonExtractor (which one would expect to fail with an empty query).

See the Extensions Guide.
This can be a core extractor, so you'll add a definition to the registry in validators.py

Code will be something like this + tests (not tested, yet).

class RawBodyExtractor(AbstractExtractor):
    """ Extractor that pulls out a named header """
    extractor_type = 'raw_body'  # Printable name for the type
    is_header_extractor = False  # Use headers in extraction
    is_body_extractor = True  # Uses body in extraction

    def extract_internal(self, query=None, args=None, body=None, headers=None):
        """ Return the HTTP response
        """
        return body

    @classmethod
    def parse(cls, config, extractor_base=None):
        return RawBodyExtractor()

@svanoort
Copy link
Owner

Implemented in: b06b72e

With extractor name 'raw_body"

@svanoort svanoort closed this Sep 29, 2015
@svanoort
Copy link
Owner

@alazaro It turns out that other users were also looking for this feature, and found some significant use cases that did require the full root JSON document, so I've gone ahead and added it (currently on the master branch), in addition to the raw body extractor.

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

Successfully merging this pull request may close these issues.

2 participants