November 29, 2023

PBX Science

VoIP & PBX, Networking, DIY, Computers.

The author of curl open-sources trurl: A command-line tool for parsing and manipulating URLs

3 min read

The author of curl open-sources trurl: A command-line tool for parsing and manipulating URLs



The author of curl open-sources trurl, a command-line tool for parsing and manipulating URLs

Daniel, the author of curl, announced the launch of a new open source project: trurl , a command-line tool for parsing and manipulating URLs, mainly for shell script authors. Daniel said the ‘tr’ in the project’s name stands for translate or transpose.

 

The author of curl open-sources trurl: A command-line tool for parsing and manipulating URLs

 

According to Daniel, URLs are difficult to parse and thus lead to many security issues in the software.

trurl hopes to help alleviate this problem by removing the need for script and command-line authors to reinvent the wheel here and there.

 

trurl uses libcurl’s URL parser, so it parses and understands URLs in exactly the same way as the command-line tool curl – making it the perfect companion tool.

 

Example code:

  $ trurl --url https://curl.se --set host=example.com
  https://example.com/

  $ trurl --set host=example.com --set scheme=ftp
  ftp://example.com/

  $ trurl --url https://curl.se/we/are.html --redirect here.html
  https://curl.se/we/here.html

  $ trurl --url https://curl.se/we/../are.html --set port=8080
  https://curl.se:8080/are.html

  $ trurl --url https://curl.se/we/are.html --get '{path}'
  /we/are.html

  $ trurl --url https://curl.se/we/are.html --get '{port}'
  443

  $ trurl https://example.com/hello.html --get '{scheme} {port} {path}'
  https 443 /hello.html

  $ trurl --url https://curl.se/hello --append path=you
  https://curl.se/hello/you

  $ trurl --url "https://curl.se?name=hello" --append query=search=string
  https://curl.se/?name=hello&search=string

  $ trurl --url-file url-list.txt --get '{host}'
  [one host name per URL in the input file]

  $ cat url-list.txt | trurl --url-file - --get '{host}'
  [one host name per URL in the input file]

  $ trurl "https://fake.host/hello#frag" --set user=::moo:: --json
  [
    {
      "url": "https://%3a%3amoo%3a%3a@fake.host/hello#frag",
      "scheme": "https",
      "user": "::moo::",
      "host": "fake.host",
      "port": "443",
      "path": "/hello",
      "fragment": "frag"
    }
  ]

  $ trurl "https://example.com?search=hello&utm_source=tracker" --trim query="utm_*"
  https://example.com/?search=hello

What is the command of curl?

Curl is a command-line tool for transferring data using various protocols such as HTTP, FTP, SMTP, etc.

Here are some common commands that you can use with curl:

To send an HTTP GET request to a URL:

curl <url>

To send an HTTP POST request with form data:

curl -d "param1=value1&param2=value2" -X POST <url>

To send an HTTP POST request with a JSON payload:

curl -d '{"key1":"value1", "key2":"value2"}' -H "Content-Type: application/json" -X POST <url>

To download a file:

curl -O <url>


Disclaimer of pbxscience.com

Copyright © All rights reserved. | Newsphere by AF themes.