Giter Site home page Giter Site logo

Comments (17)

milo avatar milo commented on September 22, 2024

Hi @mike503 . Thank you for the bug report. Unfortunately I cannot reproduce it by:

use Milo\Github;

$api = new Github\Api(new Github\Http\CurlClient);
$response = $api->get('/repos/milo/github-api/commits/master');
var_dump($response->getContent());

the result is:

string(6797) "{"sha":"4e61e272ac71cf0420cd17de5b43cf2c04819be2","commit"............"

which is plain response body, the valid JSON.

May I ask you to send me a dump of buggy content? From begin and whole headers. Dumped in CurlClient class, before line:

var_dump($result);
list($headersStr, $content) = explode("\r\n\r\n", $result, 2) + ['', ''];

After that, could you try to replace code in Http\CurlClient.php?:

# remove
list($headersStr, $content) = explode("\r\n\r\n", $result, 2) + ['', ''];

# replace by
$size = curl_getinfo($this->curl, CURLINFO_HEADER_SIZE);
$headersStr = rtrim(substr($result, 0, $size));
$content = substr($result, $size);

from github-api.

mike503 avatar mike503 commented on September 22, 2024

I think there's a typo now... :)

I think this would fix?

- list($name, $value) = explode(': ', $header);
+ list($name, $value) = explode(': ', $headersStr);

from github-api.

mike503 avatar mike503 commented on September 22, 2024

Also was just told about this, there is a CURLOPT_HEADERFUNCTION (not sure in which version it is introduced) that allows for you to receive the headers and process them in a callback, WITHOUT having to use CURLOPT_HEADER that would spit it out in the return.

http://ontodevelopment.blogspot.com/2011/04/curloptheaderfunction-tutorial-with.html

from github-api.

milo avatar milo commented on September 22, 2024

@mike503 About the typo... could you send link to the source?

from github-api.

milo avatar milo commented on September 22, 2024

And about CURLOPT_HEADERFUNCTION... Current solution works fine. I have no reason to complicate it for now.

from github-api.

mike503 avatar mike503 commented on September 22, 2024

Whoops. Ignore that last comment. I missed a line when I was reporting that.

Yes, changing to that header callback would complicate a little bit, I suppose. But you would never have to worry about wonky header stuff messing things up again. :)

I am grabbing your project via Composer, which is grabbing it (I believe) via packagist. Do you know how long it takes for your git commits to get out there? I ran composer update and it said there was nothing new.

from github-api.

milo avatar milo commented on September 22, 2024

@mike503 I didn't tagged version, so you must use @dev. Packagist already has current master. But I don't know, sometimes it takes 10 or 15 minutes.

from github-api.

milo avatar milo commented on September 22, 2024

But you would never have to worry about wonky header stuff messing things up again

I'll think about that. Must check the compatibility and so on... Thank's for the tip anyway!

from github-api.

milo avatar milo commented on September 22, 2024

@mike503 Implemented 2de95e7

from github-api.

mike503 avatar mike503 commented on September 22, 2024

yeah I noticed. that's awesome! I will need to get composer to grab the dev from you properly tomorrow. :)

from github-api.

mike503 avatar mike503 commented on September 22, 2024

I think I see part of the problem :)

I am behind a corporate proxy (basic Squid-style) and I get multiple lines of HTTP status code output.

I am using the latest including your ec5a8ae with trim() and still get:

Notice: Undefined offset: 1 in /home/mike503/web/site/vendor/milo/github-api/src/Github/Http/CurlClient.php on line 83

This is actually the raw stuff I get back (and this is probably why the original way you were parsing it was breaking - because it issues TWO different "\r\n\r\n" style delimiters)

This is the HTTP response I get for a simple $response = $api->get("/repos/my-repo/repo/commits?since=timestamp");

HTTP/1.1 200 Connection established

HTTP/1.1 200 OK
Server: GitHub.com
Date: Wed, 01 Oct 2014 08:54:07 GMT
Content-Type: application/json; charset=utf-8
Status: 200 OK
X-RateLimit-Limit: 5000
X-RateLimit-Remaining: 4996
X-RateLimit-Reset: 1412157027
Cache-Control: private, max-age=60, s-maxage=60
Last-Modified: Wed, 01 Oct 2014 08:44:02 GMT
ETag: "878f29d52dddd01ccf16658b376e64f1"
X-OAuth-Scopes: gist, notifications, read:org, read:public_key, read:repo_hook, repo, user
X-Accepted-OAuth-Scopes: 
Vary: Accept, Authorization, Cookie, X-GitHub-OTP
X-GitHub-Media-Type: github.v3; format=json
X-XSS-Protection: 1; mode=block
X-Frame-Options: deny
Content-Security-Policy: default-src 'none'
Content-Length: 31331
Access-Control-Allow-Credentials: true
Access-Control-Expose-Headers: ETag, Link, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval
Access-Control-Allow-Origin: *
X-GitHub-Request-Id: 86868147:13AF:246E8960:542BC22F
Strict-Transport-Security: max-age=31536000; includeSubdomains; preload
X-Content-Type-Options: nosniff
Vary: Accept-Encoding
X-Served-By: 6d7de9f6458146ac34ea2a8d72ba3141

from github-api.

mike503 avatar mike503 commented on September 22, 2024

Before you explode(':') you should probably check if the line has a colon?

if (strstr($line, ':')) {
  list($name, $value) = explode(':', $line, 2);
  $responseHeaders[trim($name)] = trim($value);
}

no desireable HTTP header should leave that out anyway.

someday I will get my git-fu up and send a PR, but that's such a minor change... I just tried it and viola, all of a sudden I get expected results. :)

from github-api.

milo avatar milo commented on September 22, 2024

@mike503 I see! Thank you for debugging.

from github-api.

milo avatar milo commented on September 22, 2024

@mike503 Fixed by 89dd5ff

from github-api.

mike503 avatar mike503 commented on September 22, 2024

I believe the first part is the connection from client -> proxy server using SSL, and curl reporting the connection was successful there. Then the next hop is the actual request. Kinda funky and not many people seem to parse for that in all the curl header splitting I've seen. I'm actually going to adopt this myself for my PHP areas that need headers in a more sane, structured way. :)

from github-api.

milo avatar milo commented on September 22, 2024

As I read docs, client to proxy is HTTP. Than client calls CONNECT and proxy returns HTTP/1.1 Connection Established (+ my proxy returns Proxy-Agent: Apache 2.2 header). Then SSL connection is tunneled untouched through proxy. And cURL returns response headers and body.

from github-api.

mike503 avatar mike503 commented on September 22, 2024

Yeah, now that I think about it, it does seem to be HTTP -> PROXY -> HTTPS -> GITHUB.

Either way, curl handles it well, we just needed to process the headers better. I'm surprised I am not bitten by this more, I must not use many things which care about headers. Thanks for the quick turnaround though, I can now use this for my project. :)

from github-api.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.