ArticleslgStudy

computer science

WEBrick

WEBrick is a computer science topic covered in the lgStudy science library. This page brings together a partial reference excerpt, illustrations, worked examples, real-world applications and a short study plan, so you can understand WEBrick rather than just read about it. In short: WEBrick is a Ruby library providing simple HTTP web servers. It uses basic access authentication and digest access authentication for different kinds of servers that it can create - HTTP based server, HTTPS server, proxy server and virtual-host server.

Key takeaways

  • WEBrick belongs to computer science; place it in that map before memorising details.
  • Learn the definition first, then one example that makes the definition concrete.
  • Connect WEBrick to a quantity you can measure, compute or draw — that is where exam questions come from.
  • Reproduce the core statement of WEBrick from memory before moving on to harder problems.

Reference excerpt

WEBrick is a Ruby library providing simple HTTP web servers. It uses basic access authentication and digest access authentication for different kinds of servers that it can create - HTTP based server, HTTPS server, proxy server and virtual-host server. Construction of several non-HTTP servers such as the Day Time Server which uses the Daytime Protocol rather than the HTTP is also facilitated by WEBrick. It is used by the Ruby on Rails and Padrino frameworks to test applications in a development environment as well as production mode for small loads. It is now a part of Ruby standard library. WEBrick follows open-source distribution model.

History WEBrick has originated from an idea in an article named "Internet Programming with Ruby" in Open Design, a Japanese Engineering magazine. It was initially developed as a toolkit for the development of HTTP servers using Ruby. Due to the nature of open source model and contributions from several Ruby developers across the world, WEBrick was greatly augmented and was eventually bundled as a standard library from Ruby 1.8.0. The WEBrick ERB Handler and WEBrick Proxy Server were first introduced in Ruby 1.9.3, while the WEBrick Virtual Host was included from Ruby 2.0.0.

Usage A WEBrick server understands only the language of servlets Archived 2016-09-30 at the Wayback Machine. It uses multiple independent servlets, joined together by the programmer, for handling CGI scripts, ERB pages, Ruby Blocks and directory listings to provide a web application or to service a request URI on a per-host or per-path basis. For example, HTTPServlet::FileHandler, [1], HTTPServlet::CGIHandler, HTTPServlet::ERBHandler are the examples of the standard servlets that WEBrick comes with. WEBrick is included in Ruby and hence is available to the user at no additional cost. WEBrick has been written completely in Ruby and supports several standards such as HTTP, HTML and even RHTML. During the development stage, there is no necessity for the installation of a discrete web server since WEBrick is already built into the Rails framework. It is the default web server when the Ruby application is deployed without any procfile on Rails. Furthermore, since being implemented entirely in Ruby, direct calls can be made from WEBrick to the Rails application. On the whole, it provides a reliable, low configuration option for testing in development.

Instantiating servers

Instantiating an HTTP server The following commands are used to start an HTTP Server at the required port.

Servlets can be mounted to provide advanced custom behavior as compared to a proc, to increase the modularity.

Starting a virtual host WEBrick creates a listening port. Various other ports as ‘virtual hosts’ can also be created at the same time which do not listen as shown below:

:DocumentRoot should be provided or an instance of a servlet should be set up to service a request URI; otherwise a 404 error will be returned.

Instantiating an HTTPS server By just enabling SSL and providing an SSL certificate name, an HTTPS server can be initiated with a self-signed certificate that changes with every restart of the server.

However, a pre-determined key and certificate can also be provided for instantiating HTTPS Server as shown below:

Starting a proxy server WEBrick can also proxy GET, HEAD and POST requests:

Limitations Unlike most of the servers that are used in production, WEBrick is not scalable since it is a single threaded web server by default. Hence, multiple requests at the same time cannot be handled and the subsequent requests would have to wait till all the previous requests have been handled, incurring a large delay. Hence, developers prefer other multi-threaded full-fledged web servers like lighttpd and Mongrel for deploying their Rails applications.

See also Apache lighttpd Mongrel (web server) nginx

References

External links Gnome's Guide to WEBrick Ruby Standard Library doc - WEBrick WEBrick High Performance

Worked examples

Example 1 — a first encounter with WEBrick

Start with the simplest possible case. Write down what WEBrick claims or describes in one sentence, then invent the smallest concrete situation in which that sentence is true. In computer science, the smallest case is usually a single object, a single equation or a single measurement. Check that every symbol or term in your sentence has a meaning in that case.

Example 2 — changing one variable

Take the situation from Example 1 and change exactly one quantity: double it, halve it, or set it to zero. Predict what should happen to WEBrick before you calculate. Comparing your prediction with the result is the fastest way to find out whether you understand the idea or only the words.

Example 3 — an exam-style question

Typical questions about WEBrick ask you to (a) state it precisely, (b) apply it to given data, and (c) explain a limitation. Practise writing all three answers in under five minutes; the third part is what separates a full-mark answer from an average one.

Applications of WEBrick

In research
WEBrick appears in computer science research whenever the underlying quantities have to be modelled precisely. Papers usually cite it as a starting assumption and then explore where it breaks down.
In technology and industry
Engineering practice reuses WEBrick in design rules, simulations and safety margins. Knowing the idea lets you read a specification sheet and understand why the numbers look the way they do.
In the classroom
WEBrick is common in secondary-school and first-year university syllabi. It links to neighbouring topics Free web server software, Ruby (programming language), Web server software for Linux, so understanding it makes those chapters shorter.
In everyday life
Look for WEBrick outside the textbook — in sport, cooking, traffic, electronics or the sky above you. An example you found yourself is remembered far longer than one you were given.
Ask Teacher Smith questions about this articleOpens your AI tutor with a question about “WEBrick” →

How to study WEBrick in 20 minutes

  1. Read the reference excerpt below once, without taking notes.
  2. Close the page and write down what WEBrick means in your own words.
  3. Compare your version with the excerpt and mark what you missed.
  4. Work through the three examples above with pen and paper.
  5. Explain WEBrick out loud to somebody else — or to Teacher Smith in the lgStudy chat.

Frequently asked questions

What is WEBrick in simple terms?

WEBrick is a Ruby library providing simple HTTP web servers. It uses basic access authentication and digest access authentication for different kinds of servers that it can create - HTTP based server, HTTPS server, proxy server and virtual-host server.

Why does WEBrick matter?

Because it connects several computer science ideas at once: it gives you a definition you can apply, a quantity you can calculate, and a way to check whether a result is plausible.

How should I study WEBrick?

Read the excerpt, restate it from memory, then work through the examples and applications listed on this page. The five-step study plan above takes about twenty minutes.

What does this page cover?

It gives you a compact reference excerpt plus original lgStudy explanations, examples, applications and study material on WEBrick.

Tags

  • Free web server software
  • Ruby (programming language)
  • Web server software for Linux

Keep exploring