jsdelivr / globalping-cli

A simple CLI tool to run networking commands remotely from hundreds of globally distributed servers
Mozilla Public License 2.0
144 stars 13 forks source link

--json not working when piped #57

Closed MartinKolarik closed 1 year ago

MartinKolarik commented 1 year ago
$ globalping http https://cdn.jsdelivr.net/npm --method GET --limit 10 --json > /tmp/j
$ cat /tmp/j
> EU, NL, Lelystad, ASN:53356, Free Range Cloud
Invalid URL. The URL structure is /npm/package@version/file.js

> OC, AU, Sydney, ASN:30081, CacheNetworks, Inc.
Invalid URL. The URL structure is /npm/package@version/file.js

> AS, BD, Tungi, ASN:147181, Flarezen Ltd.
Invalid URL. The URL structure is /npm/package@version/file.js

> EU, RU, Moscow, ASN:51659, LLC Baxet
Invalid URL. The URL structure is /npm/package@version/file.js

> EU, BG, Sofia, ASN:59729, ITL LLC
Invalid URL. The URL structure is /npm/package@version/file.js

> AS, JP, Tokyo, ASN:16509, Amazon.com, Inc. (aws-ap-northeast-1)
Invalid URL. The URL structure is /npm/package@version/file.js

> EU, PL, Warsaw, ASN:61251, Host4Biz sp. z o.o.
Invalid URL. The URL structure is /npm/package@version/file.js

> AS, TR, Bahcelievler, ASN:202422, G-Core Labs S.A.
Invalid URL. The URL structure is /npm/package@version/file.js

> NA, CA, Montreal, ASN:62788, Karl Morin Holdings Inc.
Invalid URL. The URL structure is /npm/package@version/file.js

> OC, AU, Sydney, ASN:396982, Google LLC (gcp-australia-southeast1)
Invalid URL. The URL structure is /npm/package@version/file.js
MartinKolarik commented 1 year ago

Please also test that all other options are also correctly applied for both scenarios.

didil commented 1 year ago

@MartinKolarik with the current version in master:

$ go run main.go http https://cdn.jsdelivr.net/npm --method GET --limit 10 --json > /tmp/j
> NA, CA, Montreal, ASN:577, Bell Canada
> EU, RU, Moscow, ASN:48108, Sole trader Malkov Dmitrii Vladimirovich
> EU, RU, Moscow, ASN:202984, Chernyshov Aleksandr Aleksandrovich
> EU, RU, Moscow, ASN:62222, QuickSoft LLC
> EU, ES, Murcia, ASN:200845, AVATEL TELECOM, SA
> EU, BG, Sofia, ASN:61098, Akenes SA
> EU, NL, Amsterdam, ASN:60841, BerryByte Limited
> NA, US, (NY), Staten Island, ASN:26548, Purevoltage Enterprises
> EU, GB, Maidstone, ASN:5089, Virgin Media Limited
> NA, US, (TX), Dallas, ASN:30081, CacheNetworks, Inc.
$ cat /tmp/j
Invalid URL. The URL structure is /npm/package@version/file.js

Invalid URL. The URL structure is /npm/package@version/file.js

Invalid URL. The URL structure is /npm/package@version/file.js

Invalid URL. The URL structure is /npm/package@version/file.js

Invalid URL. The URL structure is /npm/package@version/file.js

Invalid URL. The URL structure is /npm/package@version/file.js

Invalid URL. The URL structure is /npm/package@version/file.js

Invalid URL. The URL structure is /npm/package@version/file.js

Invalid URL. The URL structure is /npm/package@version/file.js

Invalid URL. The URL structure is /npm/package@version/file.js

Is this the expected output ?

MartinKolarik commented 1 year ago

No, compare the following two. There should not be any difference in the output.

No piping, correct:

go run main.go http https://cdn.jsdelivr.net/npm --method GET --json
{"id":"R5vMRQ8UGC3zPhH3","type":"http","status":"finished","createdAt":"2023-05-02T11:51:47.780Z","updatedAt":"2023-05-02T11:51:48.392Z","probesCount":1,"results":[{"probe":{"continent":"EU","region":"Northern Europe","country":"GB","state":null,"city":"Maidstone","asn":50
89,"longitude":0.5167,"latitude":51.2667,"network":"Virgin Media Limited","tags":[],"resolvers":["private"]},"result":{"status":"finished","resolvedAddress":"151.101.1.229","headers":{"connection":"close","content-length":"62","access-control-allow-origin":"*","access-cont
rol-expose-headers":"*","timing-allow-origin":"*","cache-control":"public, max-age=86400, s-maxage=86400","cross-origin-resource-policy":"cross-origin","x-content-type-options":"nosniff","strict-transport-security":"max-age=31536000; includeSubDomains; preload","content-ty
pe":"text/plain; charset=utf-8","etag":"W/\"3e-rVTZaEP/IducDerMLIXX9cqTIf0\"","accept-ranges":"bytes","date":"Tue, 02 May 2023 11:51:48 GMT","age":"53136","x-served-by":"cache-fra-eddf8230061-FRA, cache-lhr7350-LHR","x-cache":"HIT, HIT","vary":"Accept-Encoding","alt-svc":"
h3=\":443\";ma=86400,h3-29=\":443\";ma=86400,h3-27=\":443\";ma=86400"},"rawHeaders":"Connection: close\nContent-Length: 62\nAccess-Control-Allow-Origin: *\nAccess-Control-Expose-Headers: *\nTiming-Allow-Origin: *\nCache-Control: public, max-age=86400, s-maxage=86400\nCross
-Origin-Resource-Policy: cross-origin\nX-Content-Type-Options: nosniff\nStrict-Transport-Security: max-age=31536000; includeSubDomains; preload\nContent-Type: text/plain; charset=utf-8\nETag: W/\"3e-rVTZaEP/IducDerMLIXX9cqTIf0\"\nAccept-Ranges: bytes\nDate: Tue, 02 May 202
3 11:51:48 GMT\nAge: 53136\nX-Served-By: cache-fra-eddf8230061-FRA, cache-lhr7350-LHR\nX-Cache: HIT, HIT\nVary: Accept-Encoding\nalt-svc: h3=\":443\";ma=86400,h3-29=\":443\";ma=86400,h3-27=\":443\";ma=86400","rawBody":"Invalid URL. The URL structure is /npm/package@version
/file.js","statusCode":400,"statusCodeName":"Bad Request","timings":{"total":225,"download":59,"firstByte":20,"dns":64,"tls":57,"tcp":21},"tls":{"authorized":true,"createdAt":"2022-12-23T10:55:14.000Z","expiresAt":"2024-01-24T10:55:13.000Z","issuer":{"C":"BE","O":"GlobalSi
gn nv-sa","CN":"GlobalSign Atlas R3 DV TLS CA 2022 Q4"},"subject":{"CN":"jsdelivr.net","alt":"DNS:jsdelivr.net, DNS:*.jsdelivr.net"}},"rawOutput":"Invalid URL. The URL structure is /npm/package@version/file.js"}}]}

Piped, broken:

go run main.go http https://cdn.jsdelivr.net/npm --method GET --json > tmp; cat tmp
> OC, AU, Sydney, ASN:202422, G-Core Labs S.A.
Invalid URL. The URL structure is /npm/package@version/file.js
didil commented 1 year ago

ok thanks, I think I see where the issue is now