Code Monkey home page Code Monkey logo

uri's Introduction

uri

URI Normalizer

An RFC 3986 URI normalizer.

The public API is defined in uri.h.

Correctness

The URI components are validated, normalized, and joined according to the RFC.

  • Note: the host component is only tokenized (checked for valid characters and percent-encoding).

  • Callers must parse tokens for correctness before using them.

Example

#include <assert.h>
#include <liburi/uri.h>
#include <stdlib.h>
#include <string.h>

int main(void)
{
    struct uri *u = NULL;
    char *str = NULL;

    assert(0 == uri_new("http://[email protected]:80/path/sub?query#fragment", &u));

    assert(!strcmp(uri_scheme(u),   "http"));
    assert(!strcmp(uri_userinfo(u), "user"));
    assert(!strcmp(uri_host(u),     "example.com"));
    assert(!strcmp(uri_port(u),     "80"));
    assert(!strcmp(uri_path(u),     "/path/sub"));
    assert(!strcmp(uri_query(u),    "query"));
    assert(!strcmp(uri_fragment(u), "fragment"));

    uri_scheme_set(u, "https");
    assert(!strcmp(uri_scheme(u),   "https"));

    uri_port_set(u, NULL);

    uri_path_set(u, "other");
    assert(!strcmp(uri_path(u),     "/path/other"));

    assert(0 == uri_str(u, &str));
    assert(!strcmp(str, "https://[email protected]/path/other?query#fragment"));
    free(str);

    uri_port_set(u, "443");

    uri_query_set(u, "?");
    assert(!strcmp(uri_query(u),    "?"));

    uri_fragment_set(u, "#");
    assert(!strcmp(uri_fragment(u), "#"));

    assert(0 == uri_str(u, &str));
    assert(!strcmp(str, "https://[email protected]:443/path/other??#%23"));
    free(str);

    assert(0 == uri_set(u, "../new"));

    assert(0 == uri_str(u, &str));
    assert(!strcmp(str, "https://[email protected]:443/new"));
    free(str);

    uri_delete(u);
}

uri's People

Contributors

ianjray avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.