Skip to content

Instantly share code, notes, and snippets.

@abargnesi
Last active November 9, 2016 16:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save abargnesi/e76f33b7b781febb97d16377d8eca1ff to your computer and use it in GitHub Desktop.
Save abargnesi/e76f33b7b781febb97d16377d8eca1ff to your computer and use it in GitHub Desktop.
Induce and log instagram connection issues using curl and jq.
#!/usr/bin/env bash
API_URL="https://api.instagram.com/v1/tags/foodporn/media/recent"
TOKEN="PUT YOUR TOKEN HERE"
request_next_url() {
URL="$1"
#http2 connections seem to be immune to connection issues.
#echo $(curl --http2 --verbose "$URL" 2>> trace-http2.log | jq .pagination.next_url | tr -d '"')
echo $(curl --http1.1 --verbose "$URL" 2>> trace-http.log | jq .pagination.next_url | tr -d '"')
}
export -f request_next_url
NEXT_URL=$(request_next_url "$API_URL?access_token=$TOKEN")
echo "R: $NEXT_URL"
while [ -n "$NEXT_URL" ]; do
NEXT_URL=$(request_next_url "$NEXT_URL")
echo "R: $NEXT_URL"
done
@abargnesi
Copy link
Author

The following shows a 200 OK response where response body transfer was closed.

* Curl_http_done: called premature == 0
^M100 45202  100 45202    0     0   109k      0 --:--:-- --:--:-- --:--:--  109k
* Connection #0 to host api.instagram.com left intact    
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
^M  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0*   Tr
* TCP_NODELAY set
* Connected to api.instagram.com (31.13.71.52) port 443 (#0)
* ALPN, offering http/1.1
* Cipher selection: ALL:!EXPORT:!EXPORT40:!EXPORT56:!aNULL:!LOW:!RC4:@STRENGTH
* successfully set certificate verify locations:
*   CAfile: /etc/ssl/certs/ca-certificates.crt
  CApath: none
* TLSv1.2 (OUT), TLS header, Certificate Status (22):
} [5 bytes data]
* TLSv1.2 (OUT), TLS handshake, Client hello (1):
} [512 bytes data]
* TLSv1.2 (IN), TLS handshake, Server hello (2):
{ [108 bytes data]
* TLSv1.2 (IN), TLS handshake, Certificate (11):
{ [3063 bytes data]
* TLSv1.2 (IN), TLS handshake, Server key exchange (12):
{ [333 bytes data]
* TLSv1.2 (IN), TLS handshake, Server finished (14):
{ [4 bytes data] 
* TLSv1.2 (OUT), TLS handshake, Client key exchange (16):
} [70 bytes data]
* TLSv1.2 (OUT), TLS change cipher, Client hello (1):
} [1 bytes data] 
* TLSv1.2 (OUT), TLS handshake, Finished (20):
} [16 bytes data]
* TLSv1.2 (IN), TLS change cipher, Client hello (1):
{ [1 bytes data]
* TLSv1.2 (IN), TLS handshake, Finished (20):
{ [16 bytes data]
* SSL connection using TLSv1.2 / ECDHE-RSA-AES128-GCM-SHA256
* ALPN, server accepted to use http/1.1
* Server certificate:
*  subject: C=US; ST=CA; L=Menlo Park; O=Instagram LLC; CN=*.instagram.com
*  start date: Apr  8 00:00:00 2015 GMT
*  expire date: Dec 30 12:00:00 2016 GMT
*  subjectAltName: host "api.instagram.com" matched cert's "*.instagram.com"
*  issuer: C=US; O=DigiCert Inc; OU=www.digicert.com; CN=DigiCert SHA2 High Assurance 
*  SSL certificate verify ok.
} [5 bytes data]
> GET /v1/tags/foodporn/media/recent?access_token=...redacted...
> Host: api.instagram.com^M
> User-Agent: curl/7.51.0^M
> Accept: */*^M
> ^M
{ [5 bytes data]
< HTTP/1.1 200 OK^M
< x-ratelimit-remaining: ...redacted...^M
< Content-Language: en^M
< Expires: Sat, 01 Jan 2000 00:00:00 GMT^M
< Vary: Cookie, Accept-Language, Accept-Encoding^M
< x-ratelimit-limit: ...redacted...^M
< Pragma: no-cache^M
< Cache-Control: private, no-cache, no-store, must-revalidate^M
< Date: Wed, 09 Nov 2016 16:07:08 GMT^M
< Content-Type: application/json; charset=utf-8^M
< Set-Cookie: csrftoken=...redacted...; expires=...redacted...:
< Set-Cookie: s_network=; expires=...redacted...; Max-Age=3600; Path=/^
< Set-Cookie: sessionid=...redacted...
< Connection: keep-alive^M
< Content-Length: 49015^M
< ^M
{ [604 bytes data]
* TLSv1.2 (IN), TLS alert, Client hello (1):
{ [2 bytes data]
* transfer closed with 14190 bytes remaining to read
* Curl_http_done: called premature == 1
^M 71 49015   71 34825    0     0  93158      0 --:--:-- --:--:-- --:--:-- 93364
* Closing connection 0
} [5 bytes data]
curl: (18) transfer closed with 14190 bytes remaining to read       

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment