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

[WIP] Add query for HTTP redirects #3916

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

theoforger
Copy link
Contributor

Closes #922.

Description

This PR adds the query for redirects, allowing Hurl to look up a list of HTTP redirects evaluated as runner::HttpResponse.

(Marked as draft because it's still missing integration tests)

Copy link
Collaborator

@jcamiel jcamiel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @theoforger, some really minor changes, everything looks fine


impl Display for HttpResponse {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{:?}", self)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

{:?}should be used to implement fmt::Debug not fmt::Display... We could simply write here:

write!(f, "url={} status={}", self.url, self.status)

.iter()
.map(|r| Value::HttpResponse(HttpResponse::new(r.url.clone(), r.status)))
.collect();
values.pop();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we should add a comment here about why we pop the last values.

// `responses` is the chain list of response triggers by following redirection. We want to only keep 
// "redirected" HTTP response so we drop the last, not-redirected, response.

/// Represents an HTTP request for `Value::HttpResponse`
#[derive(Clone, Debug)]
pub struct HttpResponse {
url: Url,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should document each field, even if it's obvious:

/// URL of the request that triggers this reponse
url: Url,
/// Status code of the HTTP response
status: u32,

I'm adding this because maybe we'll need another field that will hold the potential redirection URL. I think we will need this

/// Value of the redirection URL if this response triggers a redirect
redirect_url: Optional<Url>

(I think we should distinguish the two URLs url and redirect_url)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want to include this right now or in a future PR?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can let the struct as it is actually, I think we'll need/add it when we will implement this kind of expression:

GET https://foo.com/auth
HTTP 200
redirect nth 2 url == "https://foo.com/login"

@@ -31,6 +32,8 @@ pub enum Value {
Bytes(Vec<u8>),
/// A date.
Date(chrono::DateTime<chrono::Utc>),
/// A structure to represent an HTTP redirection.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could use this structure for other scenarios so the comment should be:

/// A structure to represent an HTTP response.

@@ -102,6 +106,7 @@ impl fmt::Display for Value {
Value::Bool(x) => x.to_string(),
Value::Bytes(v) => hex::encode(v).to_string(),
Value::Date(v) => v.to_string(),
Value::HttpResponse(v) => format!("HttpResponse(status={})", v.status()),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe simply:

Value::HttpResponse(v) => v.to_string(),

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.

How to know if there has been a redirection or not ?
2 participants