Daniel speaks about the trurl command line tool at curl up 2024.
Size: 586.29 KB
Language: en
Added: May 16, 2024
Slides: 10 pages
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
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