trurl 2024 by Daniel Stenberg from curl up 2024

bagder 19 views 10 slides May 16, 2024
Slide 1
Slide 1 of 10
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9
Slide 10
10

About This Presentation

Daniel speaks about the trurl command line tool at curl up 2024.


Slide Content

2024

Problems
Parsing URLs is difficult - especially in shell scripts
Scripts using curl often need a certain amount of URL “fiddling”
Mixing URL parsers is a known recipe for security problems
@bagder

Solution
A dedicated tool for URL parsing and manipulation
A ‘tr’ for URLs
Using curl’s URL parser for consistency
A curl companion tool
@bagder

Features
-extract any URL part
-update any part of a URL
-create a URL from components
-apply a relative URL on an absolute: “do a redirect”
-extract specific pieces of the query
-trim off specific pieces of the query
-verify that the URL is valid
-output URL components as JSON
-all of this on any number of provided URL
@bagder

Examples: set
Replace the hostname of a URL
$ trurl --url https://curl.se --set host=example.com
https://example.com/

Create a URL by setting components
$ trurl --set host=example.com --set scheme=ftp
ftp://example.com/


@bagder

Examples: get
Extract the path from a URL
$ trurl --url https://curl.se/we/are.html --get '{path}'
/we/are.html

Extract the port from a URL
$ trurl --url https://curl.se/h.html --get '{default:port}'
443
@bagder

Examples: query
Remove tracking tuples from query
$ trurl "https://curl.se?search=hey&utm_source=tracker"
--trim query="utm_*"
https://curl.se/?search=hey

Show a specific query key value
$ trurl "https://example.com?a=home&here=now&thisthen" -g
'{query:a}'
home
@bagder

Development
https://github.com/curl/trurl
Managed by the curl organization
still pre 1.0 release
140+ tests
(has helped us exercise and polish the URL parser and its API)
@bagder

Status
Works
Solid
Shipped by several distros
@bagder

Future
A one-dot-zero release
What else?
@bagder