Giter VIP home page Giter VIP logo

comp6641-la01's Introduction

Requirements

The following requirements are mandatory:

  • A recent C++ compiler which fully supports C++11
  • CMake

How to Build

Note that this program depends on some libraries. CMake first download those libraries and then it builds the program.

How to Build in Linux

You can use the graphical interface of CMake (cmake-gui) to generate a makefile. If you prefer command line interface, first go to the project path and then execute the following commands:

$ mkdir build
$ cd build
$ cmake ..
$ make

For more information about using CMake check out this link.

How to Build in Windows

You can use the graphical interface of CMake to generate a project (for example Visual Studio project). If you prefer command line interface, first go to the project path and then execute the following commands:

mkdir build
cd build
cmake ..

Then you can open the generated project with your favorite IDE (e.g. Visual Studio). For more information about using CMake check out this link.

Examples

You can see various examples in the following line. For more information about available arguments run ./httpc --help.

$ ./httpc -v get "http://httpbin.org/get?course=networking&assignment=1"
$ ./httpc -v post "http://httpbin.org/post" -h "Content-Type: application/json" -d '{"Assignment": 1}'
$ ./httpc -v post "http://httpbin.org/post" -h "Content-Type: application/json" -f sample_files/post_data_1.txt
$ ./httpc -v post "http://httpbin.org/post" -h "Content-Type: application/json" -f sample_files/post_data_2.txt
$ ./httpc -v post "http://httpbin.org/post" -h "Content-Type: application/json" -h "User-Agent: Mozilla/5.0 (X11; Fedora; Linux x86_64; rv:56.0) Gecko/20100101 Firefox/56.0" -h "Accept-Language: en-US,en;q=0.7,fa;q=0.3" -f sample_files/post_data_2.txt
$ ./httpc -v post "http://httpbin.org/post" -h "Content-Type: application/x-www-form-urlencoded" -f sample_files/post_data_3.txt

You can find some sample files for --file option in sample_files directory.

Optional Tasks

Support Redirection

I implemented both absolute and relative redirection.

$ ./httpc -v --redirect get "http://httpbin.org/redirect-to?url=http://example.com"
$ ./httpc -v --redirect  get "http://httpbin.org/redirect/6"
$ ./httpc -v --redirect --max-redirection=3 get "http://httpbin.org/redirect/6"
$ ./httpc -v --redirect  get "http://httpbin.org/relative-redirect/6"
$ ./httpc -v --redirect  get "http://httpbin.org/absolute-redirect/6"

Writing The Body of The Response to a file

We can store both text and binary files using -o flag.

$ ./httpc -v  get "http://httpbin.org/image/png" -o image.png
$ ./httpc -v get "http://download.blender.org/peach/bigbuckbunny_movies/big_buck_bunny_480p_surround-fix.avi" -o big_buck_bunny.avi

Reading HTTP Header from a File

Using --header-file, you can associate the content of a file as headers for HTTP request. Since there should be an empty line between header request and the body request in POST, it can be tricky. In my implementation user can put empty lines at the end of fine but the program eliminate them. Here is an example:

$ ./httpc -v post "http://httpbin.org/post" --header-file sample_files/header_data_1.txt -f sample_files/post_data_3.txt

Third-Party Libraries

I've used the following external libraries. You don't need to download them. It's the job of CMake:

  • Asio for cross-platform socket programming
  • cxxopts for command line interface
  • LUrlParser for parsing URLs

comp6641-la01's People

Contributors

qsaman avatar

Watchers

 avatar  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.