ukma_url_parser
This Rust project provides functionality for parsing URLs and their components (such as protocol, domains, parameters, etc.) using the rust-pest library. It is designed for analyzing parts of a URL.
Description of the parsing process
A URL (Uniform Resource Locator) is the address of a unique resource on the internet. It is one of the key mechanisms used by browsers to retrieve resources such as HTML pages, CSS documents, images, and more. This library parses URL parts step-by-step, so it is crucial to understand the structure of a URL:
- file - File URI scheme
- ftp – File Transfer Protocol
- http – Hypertext Transfer Protocol
- https – Hypertext Transfer Protocol Secure
- imap – Internet Message Access Protocol
- irc – Internet Relay Chat
- nntp – Network News Transfer Protocol
As well as many lesser known schemes like:
- acap – Application Configuration Access Protocol
- icap – Internet Content Adaptation Protocol
- mtqp – Message Tracking Query Protocol (RFC3887)
- wss – Encrypted WebSocket connections
A scheme is required for a URL address.
Technical aspects of parsing:
For parsing purposes, created an enum of all official protocols and method that returns their string value. The first rule of this parser checks whether a provided string is a valid URL scheme. It is important to mention, that URL scheme is case insensitive.
Technical aspects of parsing:
A domain name is required for a URL address. A label is a part of a domain name, separated by a dot ("."). For simplicity, domain names and subdomains are parsed into a general vector as string values.
Technical aspects of parsing:
A port number is a 16-bit unsigned integer that ranges from 0 to 65535. So this is how it is parsed. A port value separated from a domain value by a colon. A port can be optional.
Technical aspects of parsing:
The path can be optional. It is stored as list of strings. Example: /page/new/3
Technical aspects of parsing:
Parameters are parsed as hashmap with key value structure (Key and value are strings).
Technical aspects of parsing:
It is parsed as a usual string/
Useful commands (using Makefile)
Run a project with a test file (urls.txt)
make run
Run tests
make test
Format code
make fmt
Analyse code
make clippy
Open docs
make doc
Get help
make help