You are on page 1of 7

WD paper solution.

Q.1

A) What is HTTP? Explain HTTP Header with example.


 HTTP: is a protocol for fetching resources such as HTML
documents. It is the foundation of any data exchange on the
Web.

 HTTP header: HTTP headers let the client and the server pass
additional information with an HTTP request or response. An
HTTP header consists of its case-insensitive name followed by a
colon (:), then by its value.

 HTTP header types:


Headers can be grouped according to their contexts:
1. Request headers: contain more information about the resource
to be fetched, or about the client requesting the resource.
2. Response headers: hold additional information about the
response, like its location or about the server providing it.
3. Representation headers: contain information about the body
of the resource, like its MIME type, or encoding/compression
applied.
4. Payload headers: contain representation-independent
information about payload data, including content length and
the encoding used for transport.

 Ex:
PUT /demo/program HTTP/1.1
Host: original.sample.com
Content-Type: video/h264
Content-Length: 2342564178765
Expect: 100-continue

B) Explain the Architecture of Web Browser.


 The web browser is an application software to explore www (World
Wide Web). It provides an interface between the server and the client
and requests to the server for web documents and services. It works as a
compiler to render HTML which is used to design a webpage. Whenever
we search anything on the internet, the browser loads a web page
written in HTML, including text, links, images, and other items such as
style sheets and JavaScript functions. Google Chrome, Microsoft Edge,
Mozilla Firefox, Safari are examples of web browsers.
1. The User Interface: The user interface is the space
where User interacts with the browser. It includes the
address bar, back and next buttons, home button, refresh
and stop, bookmark option, etc. Every other part, except the
window where requested web page is displayed, comes under
it.

2. The Browser Engine: The browser engine works as a


bridge between the User interface and the rendering engine.
According to the inputs from various user interfaces, it
queries and manipulates the rendering engine.

3. The Rendering Engine: The rendering engine, as the


name suggests is responsible for rendering the requested
web page on the browser screen. The rendering engine
interprets the HTML, XML documents and images that are
formatted using CSS and generates the layout that is
displayed in the User Interface. However, using plugins or
extensions, it can display other types data also. Different
browsers user different rendering engines:
* Internet Explorer: Trident
* Firefox & other Mozilla browsers: Gecko
* Chrome & Opera 15+: Blink
* Chrome (iPhone) & Safari: Webkit

4. Networking: Component of the browser which retrieves


the URLs using the common internet protocols of HTTP or
FTP. The networking component handles all aspects of
Internet communication and security. The network
component may implement a cache of retrieved documents
in order to reduce network traffic.

5. JavaScript Interpreter: It is the component of the


browser which interprets and executes the javascript code
embedded in a website. The interpreted results are sent to
the rendering engine for display. If the script is external then
first the resource is fetched from the network. Parser keeps
on hold until the script is executed.

6. UI Backend: UI backend is used for drawing basic


widgets like combo boxes and windows. This backend
exposes a generic interface that is not platform specific. It
underneath uses operating system user interface methods.

7. Data Persistence/Storage: This is a persistence layer.


Browsers support storage mechanisms such as localStorage,
IndexedDB, WebSQL and FileSystem. It is a small database
created on the local drive of the computer where the browser
is installed. It manages user data such as cache, cookies,
bookmarks and preferences.

C) What is CORS? Write code to implement simple cross-origin resource


sharing and wildcards.
 Cross-Origin Resource Sharing (CORS) is an HTTP-
header based mechanism that allows a server to indicate
any origins (domain, scheme, or port) other than its own
from which a browser should permit loading resources.
 Two types:
1. Simple request.
2. Preflight request.
 For example, suppose web content
at https://foo.example wishes to invoke content on
domain https://bar.other. Code of this sort might be used
in JavaScript deployed on foo.example:

 const xhr = new XMLHttpRequest();


const url = 'https://bar.other/resources/public-data/';

xhr.open('GET', url);
xhr.onreadystatechange = someHandler;
xhr.send();

 Let's look at what the browser will send to the server in


this case, and let's see how the server responds:

GET /resources/public-data/ HTTP/1.1


Host: bar.other
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X
10.14; rv:71.0) Gecko/20100101 Firefox/71.0
Accept:
text/html,application/xhtml+xml,application/xml;q=0.9,*
/*;q=0.8
Accept-Language: en-us,en;q=0.5
Accept-Encoding: gzip,deflate
Connection: keep-alive
Origin: https://foo.example

 The request header of note is Origin, which shows that the


invocation is coming from https://foo.example.

HTTP/1.1 200 OK
Date: Mon, 01 Dec 2008 00:23:53 GMT
Server: Apache/2
Access-Control-Allow-Origin: *
Keep-Alive: timeout=2, max=100
Connection: Keep-Alive
Transfer-Encoding: chunked
Content-Type: application/xml

[…XML Data…]

 In response, the server returns a Access-Control-Allow-


Origin header with Access-Control-Allow-Origin: *, which
means that the resource can be accessed by any origin.
Q.2
A)

You might also like