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

Track redirects followed by curl #2

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

Zegnat
Copy link
Contributor

@Zegnat Zegnat commented May 4, 2018

Three commits:

  1. Implement a CURLOPT_HEADERFUNCTION that keeps track of all headers coming in, and when curl switches to a different URL logs this as a redirect.

  2. Reimplement the debug property coming out of the transport, because the CURLOPT_HEADERFUNCTION took all headers away from the standard response. As all lines parsed by the header function can be added to debug now, it will actually show all responses (with their headers) along the redirect path. In a way it has become even more complete.

  3. Use the syntax expected by aaronpk/indielogin.com for the redirect array:

     $redirects[] = [
       'code' => $response->getStatusCode(),
       'from' => ''.$request->getUri(),
       'to' => ''.$uri
     ];

All of this is also detailed in the commit messages.

Zegnat added 3 commits May 4, 2018 15:59
CURLOPT_HEADERFUNCTION is the recommended method for collecting the
response headers. Because every request in the redirect chain contains
headers (at the minimum a location line), we can track which URL’s
headers are being parsed and collect a history of URLs.
Rebuild the debug property from the raw headers passed to the new
CURLOPT_HEADERFUNCTION and the response body. This will match the raw
HTTP response more than previously. It will also contain all the
redirecting steps and HTTP status lines.
Taking the format that @aaronpk has used for aaronpk/IndieLogin.com.
Also make sure the redirect array gets cleared at the first request,
just in case the transport object is reused.
@Zegnat
Copy link
Contributor Author

Zegnat commented May 4, 2018

To clarify, the only API change is that if Curl is used as the transport system the output will contain 1 extra key in the array: redirects. This contains an array with sub arrays following the one detailed above.

I’ll do another commit with an updated README.

@Zegnat
Copy link
Contributor Author

Zegnat commented May 5, 2018

Hopefully that README change clears things up, @aaronpk!

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.

None yet

1 participant