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

Enable HttpRequestTask to validate response codes #824

Closed
manarth opened this issue Dec 28, 2017 · 3 comments
Closed

Enable HttpRequestTask to validate response codes #824

manarth opened this issue Dec 28, 2017 · 3 comments

Comments

@manarth
Copy link
Contributor

manarth commented Dec 28, 2017

The http-request task offers a parameter to validate the response body against a regex, but the http status code is not provided or checked.

This differs from the httpget task, which raises a Build failure if the response code is not 200.

It would be useful to have a way to validate that the response-code matched expectations. This could be implemented in a similar way to the responseRegex parameter.

  <!-- Accept any 2xx response as valid. -->
  <http-request url="http://example.com/" responseCodeRegex="/^2\d{2}$/" />
@siad007
Copy link
Member

siad007 commented Dec 28, 2017

It seems to me, that this behavior is covered by the http condition i.e.

<if>
    <http url="http://example.com/" errorsBeginAt="404" />
    <then>
        <!-- do something... -->
    </then>
</if>

Would this cover your needs?

@manarth
Copy link
Contributor Author

manarth commented Dec 28, 2017

The httpget task will throw a build exception, but the http-request task doesn't check the status code in any way, so even if it encounters an error, it doesn't stop the build.

I've created a PR which adds these checks - #826

@manarth
Copy link
Contributor Author

manarth commented Dec 28, 2017

In retrospect, you're right: my particular use-case is covered by the http condition (I'm pinging a server before attempting a large number of requests).

The PR may potentially be useful to other use-cases though (e.g. using http-request to post to an API, and verify something like a 201).

@siad007 siad007 added this to the 3.0 RC1 milestone Dec 28, 2017
@mrook mrook modified the milestones: 3.0.0-alpha1, 3.0.0-alpha2 Mar 15, 2018
@mrook mrook closed this as completed in 4043609 Jun 11, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

3 participants