71
CURL CURL YLMRX YLMRX Created: 2019-07-03 Wed 11:43 1

CURLCURL - Pass the SALT Conference · DevTools (Firefox, Chrome) is good httpie is neater/prettier python-requests. SOME ANSSOME ANSWERSWERS Old means: Good Stable/reliable DevTools

  • Upload
    others

  • View
    3

  • Download
    0

Embed Size (px)

Citation preview

Page 1: CURLCURL - Pass the SALT Conference · DevTools (Firefox, Chrome) is good httpie is neater/prettier python-requests. SOME ANSSOME ANSWERSWERS Old means: Good Stable/reliable DevTools

CURLCURLYLMRXYLMRX

Created: 2019-07-03 Wed 11:43

1

Page 2: CURLCURL - Pass the SALT Conference · DevTools (Firefox, Chrome) is good httpie is neater/prettier python-requests. SOME ANSSOME ANSWERSWERS Old means: Good Stable/reliable DevTools

ABOUTABOUTYoann "fuzzy" Lamouroux:

Reverse-engineer and security expert @dataimpact(we're hiring ��� )Former sysadminTrol ˆ Wdocumented opinions:

xoxopowo@twitter

[email protected]

Page 3: CURLCURL - Pass the SALT Conference · DevTools (Firefox, Chrome) is good httpie is neater/prettier python-requests. SOME ANSSOME ANSWERSWERS Old means: Good Stable/reliable DevTools

ABOUT LAST YEARABOUT LAST YEAR

Page 4: CURLCURL - Pass the SALT Conference · DevTools (Firefox, Chrome) is good httpie is neater/prettier python-requests. SOME ANSSOME ANSWERSWERS Old means: Good Stable/reliable DevTools

ABOUT LAST YEARABOUT LAST YEAR5' is short (except when prod is down)

Page 5: CURLCURL - Pass the SALT Conference · DevTools (Firefox, Chrome) is good httpie is neater/prettier python-requests. SOME ANSSOME ANSWERSWERS Old means: Good Stable/reliable DevTools

ABOUT LAST YEARABOUT LAST YEAR5' is short (except when prod is down)Now I have 20 (w00t)

Page 6: CURLCURL - Pass the SALT Conference · DevTools (Firefox, Chrome) is good httpie is neater/prettier python-requests. SOME ANSSOME ANSWERSWERS Old means: Good Stable/reliable DevTools

ABOUT LAST YEARABOUT LAST YEAR5' is short (except when prod is down)Now I have 20 (w00t)I hope I deal better with time

Page 7: CURLCURL - Pass the SALT Conference · DevTools (Firefox, Chrome) is good httpie is neater/prettier python-requests. SOME ANSSOME ANSWERSWERS Old means: Good Stable/reliable DevTools

ABOUT LAST YEARABOUT LAST YEAR5' is short (except when prod is down)Now I have 20 (w00t)I hope I deal better with time(so I made a slide about dealing with time)

Page 8: CURLCURL - Pass the SALT Conference · DevTools (Firefox, Chrome) is good httpie is neater/prettier python-requests. SOME ANSSOME ANSWERSWERS Old means: Good Stable/reliable DevTools

ABOUT LAST YEARABOUT LAST YEAR5' is short (except when prod is down)Now I have 20 (w00t)I hope I deal better with time(so I made a slide about dealing with time)No more curling jokes (sorry)

Page 9: CURLCURL - Pass the SALT Conference · DevTools (Firefox, Chrome) is good httpie is neater/prettier python-requests. SOME ANSSOME ANSWERSWERS Old means: Good Stable/reliable DevTools

TRIVIATRIVIAProject started in 1996Still maintained by Daniel Stenberg (@badger)libcurl for about every language out thereThe curl binary is in EVERY default install

Page 10: CURLCURL - Pass the SALT Conference · DevTools (Firefox, Chrome) is good httpie is neater/prettier python-requests. SOME ANSSOME ANSWERSWERS Old means: Good Stable/reliable DevTools

ALL OF THEMALL OF THEM

Page 11: CURLCURL - Pass the SALT Conference · DevTools (Firefox, Chrome) is good httpie is neater/prettier python-requests. SOME ANSSOME ANSWERSWERS Old means: Good Stable/reliable DevTools

ALL OF THEMALL OF THEMGNU/Linux, *BSD

Page 12: CURLCURL - Pass the SALT Conference · DevTools (Firefox, Chrome) is good httpie is neater/prettier python-requests. SOME ANSSOME ANSWERSWERS Old means: Good Stable/reliable DevTools

ALL OF THEMALL OF THEMGNU/Linux, *BSDMacOS

Page 13: CURLCURL - Pass the SALT Conference · DevTools (Firefox, Chrome) is good httpie is neater/prettier python-requests. SOME ANSSOME ANSWERSWERS Old means: Good Stable/reliable DevTools

ALL OF THEMALL OF THEMGNU/Linux, *BSDMacOSWindows 10 (recently)

Page 14: CURLCURL - Pass the SALT Conference · DevTools (Firefox, Chrome) is good httpie is neater/prettier python-requests. SOME ANSSOME ANSWERSWERS Old means: Good Stable/reliable DevTools

SOME QUESTIONSSOME QUESTIONScurl is oldcurl is badly documented (?)DevTools (Firefox, Chrome) is goodhttpie is neater/prettierpython-requests

Page 15: CURLCURL - Pass the SALT Conference · DevTools (Firefox, Chrome) is good httpie is neater/prettier python-requests. SOME ANSSOME ANSWERSWERS Old means: Good Stable/reliable DevTools

SOME ANSWERSSOME ANSWERSOld means:

GoodStable/reliable

DevTools are indeed goodhttpie is a curl wrapperpython-requests is python (hang-on, brb)

Page 16: CURLCURL - Pass the SALT Conference · DevTools (Firefox, Chrome) is good httpie is neater/prettier python-requests. SOME ANSSOME ANSWERSWERS Old means: Good Stable/reliable DevTools

DOCUMENTATIONDOCUMENTATIONYou usually need curl in critical situationsNo time to dig through 3k lines manual

Page 17: CURLCURL - Pass the SALT Conference · DevTools (Firefox, Chrome) is good httpie is neater/prettier python-requests. SOME ANSSOME ANSWERSWERS Old means: Good Stable/reliable DevTools

EVERYWHEREEVERYWHEREDevTools won't get you far beyond the browserToday's IT imply:

Page 18: CURLCURL - Pass the SALT Conference · DevTools (Firefox, Chrome) is good httpie is neater/prettier python-requests. SOME ANSSOME ANSWERSWERS Old means: Good Stable/reliable DevTools

EVERYWHEREEVERYWHEREDevTools won't get you far beyond the browserToday's IT imply:Reverse-proxies

Page 19: CURLCURL - Pass the SALT Conference · DevTools (Firefox, Chrome) is good httpie is neater/prettier python-requests. SOME ANSSOME ANSWERSWERS Old means: Good Stable/reliable DevTools

EVERYWHEREEVERYWHEREDevTools won't get you far beyond the browserToday's IT imply:Reverse-proxiesCloudy jokes

Page 20: CURLCURL - Pass the SALT Conference · DevTools (Firefox, Chrome) is good httpie is neater/prettier python-requests. SOME ANSSOME ANSWERSWERS Old means: Good Stable/reliable DevTools

EVERYWHEREEVERYWHEREDevTools won't get you far beyond the browserToday's IT imply:Reverse-proxiesCloudy jokes(aka. mai', aka. Kloug{Front,Flare,…})

Page 21: CURLCURL - Pass the SALT Conference · DevTools (Firefox, Chrome) is good httpie is neater/prettier python-requests. SOME ANSSOME ANSWERSWERS Old means: Good Stable/reliable DevTools

EVERYWHEREEVERYWHEREDevTools won't get you far beyond the browserToday's IT imply:Reverse-proxiesCloudy jokes(aka. mai', aka. Kloug{Front,Flare,…})… whatever cool kids use these days

Page 22: CURLCURL - Pass the SALT Conference · DevTools (Firefox, Chrome) is good httpie is neater/prettier python-requests. SOME ANSSOME ANSWERSWERS Old means: Good Stable/reliable DevTools

EVERYWHEREEVERYWHEREDevTools won't get you far beyond the browserToday's IT imply:Reverse-proxiesCloudy jokes(aka. mai', aka. Kloug{Front,Flare,…})… whatever cool kids use these daysAnd shiny boxes (aka. docker)

Page 23: CURLCURL - Pass the SALT Conference · DevTools (Firefox, Chrome) is good httpie is neater/prettier python-requests. SOME ANSSOME ANSWERSWERS Old means: Good Stable/reliable DevTools

EVERYWHEREEVERYWHEREDevTools won't get you far beyond the browserToday's IT imply:Reverse-proxiesCloudy jokes(aka. mai', aka. Kloug{Front,Flare,…})… whatever cool kids use these daysAnd shiny boxes (aka. docker)Tighter firewall policy (aka. no internets)

Page 24: CURLCURL - Pass the SALT Conference · DevTools (Firefox, Chrome) is good httpie is neater/prettier python-requests. SOME ANSSOME ANSWERSWERS Old means: Good Stable/reliable DevTools

EVERYWHEREEVERYWHEREDevTools won't get you far beyond the browserToday's IT imply:Reverse-proxiesCloudy jokes(aka. mai', aka. Kloug{Front,Flare,…})… whatever cool kids use these daysAnd shiny boxes (aka. docker)Tighter firewall policy (aka. no internets)Just because you can run Chrome in docker,

Page 25: CURLCURL - Pass the SALT Conference · DevTools (Firefox, Chrome) is good httpie is neater/prettier python-requests. SOME ANSSOME ANSWERSWERS Old means: Good Stable/reliable DevTools

EVERYWHEREEVERYWHEREDevTools won't get you far beyond the browserToday's IT imply:Reverse-proxiesCloudy jokes(aka. mai', aka. Kloug{Front,Flare,…})… whatever cool kids use these daysAnd shiny boxes (aka. docker)Tighter firewall policy (aka. no internets)Just because you can run Chrome in docker,… doesn't mean you should

Page 26: CURLCURL - Pass the SALT Conference · DevTools (Firefox, Chrome) is good httpie is neater/prettier python-requests. SOME ANSSOME ANSWERSWERS Old means: Good Stable/reliable DevTools
Page 27: CURLCURL - Pass the SALT Conference · DevTools (Firefox, Chrome) is good httpie is neater/prettier python-requests. SOME ANSSOME ANSWERSWERS Old means: Good Stable/reliable DevTools
Page 28: CURLCURL - Pass the SALT Conference · DevTools (Firefox, Chrome) is good httpie is neater/prettier python-requests. SOME ANSSOME ANSWERSWERS Old means: Good Stable/reliable DevTools
Page 29: CURLCURL - Pass the SALT Conference · DevTools (Firefox, Chrome) is good httpie is neater/prettier python-requests. SOME ANSSOME ANSWERSWERS Old means: Good Stable/reliable DevTools
Page 30: CURLCURL - Pass the SALT Conference · DevTools (Firefox, Chrome) is good httpie is neater/prettier python-requests. SOME ANSSOME ANSWERSWERS Old means: Good Stable/reliable DevTools

BASICSBASICS

Display body on stdout.

>> curl https://www.example.com/

Page 31: CURLCURL - Pass the SALT Conference · DevTools (Firefox, Chrome) is good httpie is neater/prettier python-requests. SOME ANSSOME ANSWERSWERS Old means: Good Stable/reliable DevTools

VERBOSEVERBOSE curl -v https://httpbin.org > /dev/null * Rebuilt URL to: https://httpbin.org/ % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0* Trying 34.230.136.58... * TCP_NODELAY set * Connected to httpbin.org (34.230.136.58) port 443 (#0) * ALPN, offering h2 * ALPN, offering http/1.1 * successfully set certificate verify locations: * CAfile: /etc/ssl/certs/ca-certificates.crt CApath: /etc/ssl/certs } [5 bytes data] * (304) (OUT), TLS handshake, Client hello (1): } [512 bytes data] * (304) (IN), TLS handshake, Server hello (2): { [89 bytes data] * TLSv1.2 (IN), TLS handshake, Certificate (11): { [4832 bytes data] * TLSv1.2 (IN), TLS handshake, Server key exchange (12):

Page 32: CURLCURL - Pass the SALT Conference · DevTools (Firefox, Chrome) is good httpie is neater/prettier python-requests. SOME ANSSOME ANSWERSWERS Old means: Good Stable/reliable DevTools

PREFIXES:PREFIXES:* : is information> : protocol verbose FROM your computer (*)< : protocol verbose TO your computer (*)} : encrypted data FROM your computer{ : encrypted data TO your computer[xxx] : size (in bytes) of data transferred.

(ssl verbose with brackets is shown only when stdout is redirected)

(*) : doesn't mean it's not encrypted

Page 33: CURLCURL - Pass the SALT Conference · DevTools (Firefox, Chrome) is good httpie is neater/prettier python-requests. SOME ANSSOME ANSWERSWERS Old means: Good Stable/reliable DevTools

MORE VERBOSEMORE VERBOSEtcpdump might not be the answer (yet).

--trace and --trace-ascii for byte-per-byte analysis.

Use - or filename as an argument to write to stdout or to a file.

Page 34: CURLCURL - Pass the SALT Conference · DevTools (Firefox, Chrome) is good httpie is neater/prettier python-requests. SOME ANSSOME ANSWERSWERS Old means: Good Stable/reliable DevTools

CUSTOM HEADERSCUSTOM HEADERS-H (or --header) : to send custom headersAdd 'Key: Value' for each headers-A foo: is a shortcut to -H 'User-Agent: foo'-b foo=bar: is a shortcut to -H 'Cookie: foo=bar'

(Cookies are just headers your browser is used to save)

Page 35: CURLCURL - Pass the SALT Conference · DevTools (Firefox, Chrome) is good httpie is neater/prettier python-requests. SOME ANSSOME ANSWERSWERS Old means: Good Stable/reliable DevTools

COOKIESCOOKIESNot saved by defaultUse -c to save cookies to a file (- to display on stdout)Use -b to read from a file (it won't by default)

Page 36: CURLCURL - Pass the SALT Conference · DevTools (Firefox, Chrome) is good httpie is neater/prettier python-requests. SOME ANSSOME ANSWERSWERS Old means: Good Stable/reliable DevTools

TIMER AFTER TIMETIMER AFTER TIME

Page 37: CURLCURL - Pass the SALT Conference · DevTools (Firefox, Chrome) is good httpie is neater/prettier python-requests. SOME ANSSOME ANSWERSWERS Old means: Good Stable/reliable DevTools

Have-you ever seen this ?:

time curl http://example.org

Page 38: CURLCURL - Pass the SALT Conference · DevTools (Firefox, Chrome) is good httpie is neater/prettier python-requests. SOME ANSSOME ANSWERSWERS Old means: Good Stable/reliable DevTools

TRY :TRY :curl --trace-time -v http://example.org

(Only works in verbose or trace mode)

Page 39: CURLCURL - Pass the SALT Conference · DevTools (Firefox, Chrome) is good httpie is neater/prettier python-requests. SOME ANSSOME ANSWERSWERS Old means: Good Stable/reliable DevTools

TRY :TRY :curl --trace-time -v http://example.org

(Only works in verbose or trace mode)

Unless you do want to check the cpu-time / user-time of an HTTPclient request.

Page 40: CURLCURL - Pass the SALT Conference · DevTools (Firefox, Chrome) is good httpie is neater/prettier python-requests. SOME ANSSOME ANSWERSWERS Old means: Good Stable/reliable DevTools

TRY :TRY :curl --trace-time -v http://example.org

(Only works in verbose or trace mode)

Unless you do want to check the cpu-time / user-time of an HTTPclient request.

(you don't)

Page 41: CURLCURL - Pass the SALT Conference · DevTools (Firefox, Chrome) is good httpie is neater/prettier python-requests. SOME ANSSOME ANSWERSWERS Old means: Good Stable/reliable DevTools

ANOTHER APPROACHANOTHER APPROACHYou can write many variables on output, with the format string

option including:

Request information:http_code

http_version

Time and speed:time_total

speed_download

Many more…

Page 42: CURLCURL - Pass the SALT Conference · DevTools (Firefox, Chrome) is good httpie is neater/prettier python-requests. SOME ANSSOME ANSWERSWERS Old means: Good Stable/reliable DevTools

FOR EXAMPLE:FOR EXAMPLE:

Introducing -oOUTFILE, much prettier than ">/dev/null"Also introducing the -s (--silent) option to inhibit the uglyprogress metric

curl -w "http/%{http_version} %{http_code} -- %{time_total}" -s -o/dev/null http://example.com

Page 43: CURLCURL - Pass the SALT Conference · DevTools (Firefox, Chrome) is good httpie is neater/prettier python-requests. SOME ANSSOME ANSWERSWERS Old means: Good Stable/reliable DevTools

FOR EXAMPLE:FOR EXAMPLE:

Introducing -oOUTFILE, much prettier than ">/dev/null"Also introducing the -s (--silent) option to inhibit the uglyprogress metric

curl -w "http/%{http_version} %{http_code} -- %{time_total}" -s -o/dev/null http://example.com

We can also mention --stderr to control the error output

Page 44: CURLCURL - Pass the SALT Conference · DevTools (Firefox, Chrome) is good httpie is neater/prettier python-requests. SOME ANSSOME ANSWERSWERS Old means: Good Stable/reliable DevTools

FOR EXAMPLE:FOR EXAMPLE:

Introducing -oOUTFILE, much prettier than ">/dev/null"Also introducing the -s (--silent) option to inhibit the uglyprogress metric

curl -w "http/%{http_version} %{http_code} -- %{time_total}" -s -o/dev/null http://example.com

We can also mention --stderr to control the error outputUse with - to direct it to stdout

Page 45: CURLCURL - Pass the SALT Conference · DevTools (Firefox, Chrome) is good httpie is neater/prettier python-requests. SOME ANSSOME ANSWERSWERS Old means: Good Stable/reliable DevTools

FOR EXAMPLE:FOR EXAMPLE:

Introducing -oOUTFILE, much prettier than ">/dev/null"Also introducing the -s (--silent) option to inhibit the uglyprogress metric

curl -w "http/%{http_version} %{http_code} -- %{time_total}" -s -o/dev/null http://example.com

We can also mention --stderr to control the error outputUse with - to direct it to stdoutOr whatever filename

Page 46: CURLCURL - Pass the SALT Conference · DevTools (Firefox, Chrome) is good httpie is neater/prettier python-requests. SOME ANSSOME ANSWERSWERS Old means: Good Stable/reliable DevTools

FOR EXAMPLE:FOR EXAMPLE:

Introducing -oOUTFILE, much prettier than ">/dev/null"Also introducing the -s (--silent) option to inhibit the uglyprogress metric

curl -w "http/%{http_version} %{http_code} -- %{time_total}" -s -o/dev/null http://example.com

We can also mention --stderr to control the error outputUse with - to direct it to stdoutOr whatever filename>15 years using shells, still can't handle std flows ?

Page 47: CURLCURL - Pass the SALT Conference · DevTools (Firefox, Chrome) is good httpie is neater/prettier python-requests. SOME ANSSOME ANSWERSWERS Old means: Good Stable/reliable DevTools

FOR EXAMPLE:FOR EXAMPLE:

Introducing -oOUTFILE, much prettier than ">/dev/null"Also introducing the -s (--silent) option to inhibit the uglyprogress metric

curl -w "http/%{http_version} %{http_code} -- %{time_total}" -s -o/dev/null http://example.com

We can also mention --stderr to control the error outputUse with - to direct it to stdoutOr whatever filename>15 years using shells, still can't handle std flows ?curl got your back.

Page 48: CURLCURL - Pass the SALT Conference · DevTools (Firefox, Chrome) is good httpie is neater/prettier python-requests. SOME ANSSOME ANSWERSWERS Old means: Good Stable/reliable DevTools

DID YOU EVER ?DID YOU EVER ?

Page 49: CURLCURL - Pass the SALT Conference · DevTools (Firefox, Chrome) is good httpie is neater/prettier python-requests. SOME ANSSOME ANSWERSWERS Old means: Good Stable/reliable DevTools

DID YOU EVER ?DID YOU EVER ?…

Page 50: CURLCURL - Pass the SALT Conference · DevTools (Firefox, Chrome) is good httpie is neater/prettier python-requests. SOME ANSSOME ANSWERSWERS Old means: Good Stable/reliable DevTools

DID YOU EVER ?DID YOU EVER ?…

Need to edit /etc/hosts ?

Page 51: CURLCURL - Pass the SALT Conference · DevTools (Firefox, Chrome) is good httpie is neater/prettier python-requests. SOME ANSSOME ANSWERSWERS Old means: Good Stable/reliable DevTools

DID YOU EVER ?DID YOU EVER ?…

Need to edit /etc/hosts ?

curl -v --resolve www.example.com:443:1.2.3.4 https://www.example.com/

Page 52: CURLCURL - Pass the SALT Conference · DevTools (Firefox, Chrome) is good httpie is neater/prettier python-requests. SOME ANSSOME ANSWERSWERS Old means: Good Stable/reliable DevTools

DID YOU EVER ?DID YOU EVER ?…

Need to edit /etc/hosts ?

No need to play around with "Host" header

curl -v --resolve www.example.com:443:1.2.3.4 https://www.example.com/

Page 53: CURLCURL - Pass the SALT Conference · DevTools (Firefox, Chrome) is good httpie is neater/prettier python-requests. SOME ANSSOME ANSWERSWERS Old means: Good Stable/reliable DevTools

MEMORY ALLOCATIONMEMORY ALLOCATIONPROBLEMSPROBLEMS

Page 54: CURLCURL - Pass the SALT Conference · DevTools (Firefox, Chrome) is good httpie is neater/prettier python-requests. SOME ANSSOME ANSWERSWERS Old means: Good Stable/reliable DevTools

MEMORY ALLOCATIONMEMORY ALLOCATIONPROBLEMSPROBLEMS

No. Don't.

Page 55: CURLCURL - Pass the SALT Conference · DevTools (Firefox, Chrome) is good httpie is neater/prettier python-requests. SOME ANSSOME ANSWERSWERS Old means: Good Stable/reliable DevTools

MEMORY ALLOCATIONMEMORY ALLOCATIONPROBLEMSPROBLEMS

No. Don't.

All the options I mentioned can be added to $HOME/.curlrc

Page 56: CURLCURL - Pass the SALT Conference · DevTools (Firefox, Chrome) is good httpie is neater/prettier python-requests. SOME ANSSOME ANSWERSWERS Old means: Good Stable/reliable DevTools

MEMORY ALLOCATIONMEMORY ALLOCATIONPROBLEMSPROBLEMS

No. Don't.

All the options I mentioned can be added to $HOME/.curlrc

Or write several of these, and recall them with -K filename, or--config

Page 57: CURLCURL - Pass the SALT Conference · DevTools (Firefox, Chrome) is good httpie is neater/prettier python-requests. SOME ANSSOME ANSWERSWERS Old means: Good Stable/reliable DevTools

CURL PLAYS NICE WITHCURL PLAYS NICE WITHOTHERSOTHERS

Or you can avoid the options madness and ordering, by just right-clicking in Firefox (and Chrome) DevTools.

Page 58: CURLCURL - Pass the SALT Conference · DevTools (Firefox, Chrome) is good httpie is neater/prettier python-requests. SOME ANSSOME ANSWERSWERS Old means: Good Stable/reliable DevTools

CURL PLAYS NICE WITHCURL PLAYS NICE WITHOTHERSOTHERS

Or you can avoid the options madness and ordering, by just right-clicking in Firefox (and Chrome) DevTools.

And select "Copy as cURL"

Page 59: CURLCURL - Pass the SALT Conference · DevTools (Firefox, Chrome) is good httpie is neater/prettier python-requests. SOME ANSSOME ANSWERSWERS Old means: Good Stable/reliable DevTools

CURL PLAYS NICE WITHCURL PLAYS NICE WITHOTHERSOTHERS

Or you can avoid the options madness and ordering, by just right-clicking in Firefox (and Chrome) DevTools.

And select "Copy as cURL"

It works in BurpSuite too.

Page 60: CURLCURL - Pass the SALT Conference · DevTools (Firefox, Chrome) is good httpie is neater/prettier python-requests. SOME ANSSOME ANSWERSWERS Old means: Good Stable/reliable DevTools

CURL PUTS THE C IN CURL.CURL PUTS THE C IN CURL.> curl https://example.com \ --header "Hello: World" -w '# %{http_code} -- %{time_total}'\ --libcurl test.c -so/dev/null# 200 -- 0,339792%> cat test.c

Page 61: CURLCURL - Pass the SALT Conference · DevTools (Firefox, Chrome) is good httpie is neater/prettier python-requests. SOME ANSSOME ANSWERSWERS Old means: Good Stable/reliable DevTools

TEST.CTEST.C/********* Sample code generated by the curl command line tool ********** * All curl_easy_setopt() options are documented at: * https://curl.haxx.se/libcurl/c/curl_easy_setopt.html ************************************************************************/#include <curl/curl.h>

int main(int argc, char *argv[]){ CURLcode ret; CURL *hnd;struct curl_slist *slist1;

slist1 = NULL; slist1 = curl_slist_append(slist1, "Hello: World");

hnd = curl_easy_init(); curl_easy_setopt(hnd, CURLOPT_BUFFERSIZE, 102400L); curl_easy_setopt(hnd, CURLOPT_URL, "https://example.com"); curl_easy_setopt(hnd, CURLOPT_NOPROGRESS, 1L); curl_easy_setopt(hnd, CURLOPT_HTTPHEADER, slist1);

Page 62: CURLCURL - Pass the SALT Conference · DevTools (Firefox, Chrome) is good httpie is neater/prettier python-requests. SOME ANSSOME ANSWERSWERS Old means: Good Stable/reliable DevTools

YOUR OWN STRESS-TESTYOUR OWN STRESS-TESTBecause after all, they're just glorified (yet customisable)loops with precise metricsLet's roll our own apache-bench

Page 63: CURLCURL - Pass the SALT Conference · DevTools (Firefox, Chrome) is good httpie is neater/prettier python-requests. SOME ANSSOME ANSWERSWERS Old means: Good Stable/reliable DevTools

#include <curl/curl.h>#include <omp.h>#define MAX_THREAD 64#define LASERS 1000#define URL "http://www.example.com"

int main(int argc, char *argv[]) {int tid, i = 0;

FILE *devnull; devnull = fopen("/dev/null", "w");#pragma omp parallel private(i) num_threads(MAX_THREAD)

{#pragma omp for

for(i = 0; i < LASERS; ++i) { tid = omp_get_thread_num();

CURLcode ret; CURL *hnd;

double total;curl_off_t dl, rate;

Page 64: CURLCURL - Pass the SALT Conference · DevTools (Firefox, Chrome) is good httpie is neater/prettier python-requests. SOME ANSSOME ANSWERSWERS Old means: Good Stable/reliable DevTools

Just removing some comments

#include <curl/curl.h>#include <omp.h>#define MAX_THREAD 64#define LASERS 1000#define URL "http://www.example.com"

int main(int argc, char *argv[]) {int tid, i = 0;

FILE *devnull; devnull = fopen("/dev/null", "w");#pragma omp parallel private(i) num_threads(MAX_THREAD)

{#pragma omp for

for(i = 0; i < LASERS; ++i) { tid = omp_get_thread_num();

CURLcode ret; CURL *hnd;

double total;curl_off_t dl, rate;

Page 65: CURLCURL - Pass the SALT Conference · DevTools (Firefox, Chrome) is good httpie is neater/prettier python-requests. SOME ANSSOME ANSWERSWERS Old means: Good Stable/reliable DevTools

Just removing some commentsAnd wrap some OpenMP magic around

#include <curl/curl.h>#include <omp.h>#define MAX_THREAD 64#define LASERS 1000#define URL "http://www.example.com"

int main(int argc, char *argv[]) {int tid, i = 0;

FILE *devnull; devnull = fopen("/dev/null", "w");#pragma omp parallel private(i) num_threads(MAX_THREAD)

{#pragma omp for

for(i = 0; i < LASERS; ++i) { tid = omp_get_thread_num();

CURLcode ret; CURL *hnd;

double total;curl_off_t dl, rate;

Page 66: CURLCURL - Pass the SALT Conference · DevTools (Firefox, Chrome) is good httpie is neater/prettier python-requests. SOME ANSSOME ANSWERSWERS Old means: Good Stable/reliable DevTools

Just removing some commentsAnd wrap some OpenMP magic aroundCompile with: gcc mt_curl.c -fopenmp -lcurl

#include <curl/curl.h>#include <omp.h>#define MAX_THREAD 64#define LASERS 1000#define URL "http://www.example.com"

int main(int argc, char *argv[]) {int tid, i = 0;

FILE *devnull; devnull = fopen("/dev/null", "w");#pragma omp parallel private(i) num_threads(MAX_THREAD)

{#pragma omp for

for(i = 0; i < LASERS; ++i) { tid = omp_get_thread_num();

CURLcode ret; CURL *hnd;

double total;curl_off_t dl, rate;

Page 67: CURLCURL - Pass the SALT Conference · DevTools (Firefox, Chrome) is good httpie is neater/prettier python-requests. SOME ANSSOME ANSWERSWERS Old means: Good Stable/reliable DevTools

Just removing some commentsAnd wrap some OpenMP magic aroundCompile with: gcc mt_curl.c -fopenmp -lcurlMake sure the entire file is <42 LoC

#include <curl/curl.h>#include <omp.h>#define MAX_THREAD 64#define LASERS 1000#define URL "http://www.example.com"

int main(int argc, char *argv[]) {int tid, i = 0;

FILE *devnull; devnull = fopen("/dev/null", "w");#pragma omp parallel private(i) num_threads(MAX_THREAD)

{#pragma omp for

for(i = 0; i < LASERS; ++i) { tid = omp_get_thread_num();

CURLcode ret; CURL *hnd;

double total;curl_off_t dl, rate;

Page 68: CURLCURL - Pass the SALT Conference · DevTools (Firefox, Chrome) is good httpie is neater/prettier python-requests. SOME ANSSOME ANSWERSWERS Old means: Good Stable/reliable DevTools

DEMO ?DEMO ?

Page 69: CURLCURL - Pass the SALT Conference · DevTools (Firefox, Chrome) is good httpie is neater/prettier python-requests. SOME ANSSOME ANSWERSWERS Old means: Good Stable/reliable DevTools

THANK YOUTHANK YOUEveryone @ PTS for all the eventDan Stanberg for all of the curlingHave a safe trip back home ♥

Page 70: CURLCURL - Pass the SALT Conference · DevTools (Firefox, Chrome) is good httpie is neater/prettier python-requests. SOME ANSSOME ANSWERSWERS Old means: Good Stable/reliable DevTools
Page 71: CURLCURL - Pass the SALT Conference · DevTools (Firefox, Chrome) is good httpie is neater/prettier python-requests. SOME ANSSOME ANSWERSWERS Old means: Good Stable/reliable DevTools

QUESTIONS ?QUESTIONS ?���