Web server
A web server or HTTP server is a computer program that processes an application on the server side, making bidirectional or unidirectional synchronous or asynchronous connections with the client and generating or by providing a response in any client-side language or application. The code received by the client is rendered by a web browser. For the transmission of all this data some protocol is usually used. Generally, the HTTP protocol is used for these communications, belonging to the application layer of the OSI model. The term is also used to refer to the computer where these tasks are executed.
Architecture
GET request
A web server operates using the HTTP protocol, from the application layer of the OSI Model. The HTTP protocol is usually assigned TCP port 80. Requests to the server are usually made over HTTP using the GET request method, in which the resource is requested via the URL to the web server. GET /index.html HTTP/1.1
HOST: www.host.com
In the URL bar of any browser, the previous request would be analogous to the following web address:
www.host.com/index.html
Outline of a GET request
Web request
The browser, through the user interface, allows the user to make one or more web requests. The user interface or user environment is the set of browser elements that allow the request to be made actively. A web request can not only be made through a browser, but with any tool enabled for this purpose, such as a Telnet command console.
Most common user environment elements in visual web browsers:
Name | Description |
---|---|
Hyperlink, link or link | It is a portion of web content, text, image and other elements that links with a web address. By pressing a hyperlink, the browser generates an automatic GET request to the URL of that link. |
Website form | By making successful submission of the data from a form, the web browser generates an automatic GET or POST request (commonly POST) to the pair that sends the data to the server. |
Address bar | All browsers include an address bar through which you can manually access any URL, so the browser will generate an automatic GET request to that URL whenever the user wants it. |
Active Script or liabilities | Any JavaScript application has access to the status of the browser, how you can modify the data that describes such status, passively (without the user's intervention) or actively (through some user action). |
1.1 Socket to DNS address
A socket
is produced with a given server at IP address using TCP. In general, the addresses that the browser initially has are DNS addresses (alphanumeric addresses) that must be converted to numeric addresses.
1.2 DNS to IP Resolution
If the given address is DNS and there is no rule in the DNS database, the Host Resolver Request
asks the DNS server for the corresponding IP address(es). The browser creates a new rule and stores the IP address along with the DNS address in its DNS rule database.
1.3 DNS Rule Retrieval
Once the rule is stored, a request is made to the DNS database to retrieve the rule values.
1.4 Socket to IP address
A socket
with the IP address is produced using TCP. The IP address may have been retrieved in the previous step.
SOCKET 192.168.0.1
1.5 Preparing the petition
The GET request is created by setting the urlun flag priority of the request and the method (implicitly GET).
1.6 Open Cache
An entry is opened and/or created in the http cache
.
1.7 Making the request
The GET request is made. The HTTP headers of the http transaction
and later the body of the http transaction
are read.
GET /index.html HTTP/1.1
1.8 Query in Cache
The disk cache is queried for a cache entry associated with the requested resource. The values are created
(true or false) and key
(the url of the resource).
1.9 Boolean response of the existence of the requested resource
If the entry does not exist (if created is false) the data is written to the disk cache. If not, it is read directly.
2.0 Visual presentation of the resource
The operation is completed and the information is displayed on the screen (if necessary). Then in the same way, check that it is correct.
Passive GET request
Javascript allows modifications to the browser's state. The state of the browser is defined by the location object array of the global Window object. Such an object is referenced with window.location. Specifically, window.location.href contains the current address of the web browser.
If a part of the script executes such a statement:
window.location.href='http://wikipedia.org';
The browser will make such a web request without the user having mediated in said circumstance or its effects. Similarly, a new GET request will be produced if the value of window.location.search or window.location.protocol is altered.
Browser Procedure
The task of the web browser is to create the request from the data collected in the user environment of elements of the same, such as links, the value of the text of the search bar, metatags.
Entrar |
When you click on the link, the browser automatically creates the GET request and the request headers based on the metatags (defined headers), the cookies and the browser's automatic headers, and then sends them along with the request to the server..
POST request
It is the second most used type of HTTP request. The data to be sent to the server is included in the body of the same request with the correspondingly assigned HTTP headers with respect to the type of request. It is generally associated with web forms in which the data is usually encrypted to send it safely to the server.
For convention reasons, the request includes the header application/x-www-form-urlencoded
, which indicates the format or encoding of the data to be sent; this is variable->value in the format: variable=value
separated each variable->value pair by &
. This header, in HTML forms, is sent automatically, but in other web technologies such as AJAX, if you want to make a POST request correctly, the object must be specified or instantiated:
setRequestHeader("Content-type:application/x-www-form-urlencode");
ajax.send(data);
If the GET method were used, the data would have to be added to the URL, which would expose it to direct viewing.
Structure of a POST request
Typical structure of a POST request | Sample | |
Petition type |
|
|
Refer |
|
|
Content-Length |
|
|
Origin |
|
|
User-Agent |
|
|
Content-Type |
|
|
Accept |
|
|
Accept-Language |
|
|
Accept-Charset |
|
|
Cookie |
|
|
Accept-Encoding |
|
|
Contents |
|
|
Composing a POST request
The most common headers sent in a POST request:
- Petition type: Specifies the HTTP request type. (This header has no name, it is sent as)
- Refer: Specifies the url from which the POST request was made.
- Content-Length: Specifies the length in bytes of the data sent in the body of the request.
- Origin: Specifies the main url of the site.[chuckles]required]
- User-Agent:Specifies the web browser identifier from which the request was made.
- Content-Type: Specifies the format or MIME of the data sent in the body of the request.
- Accept: Specifies the MIME that is expected in the response.
- Accept-Language: Specifies the language code expected in the answer.
- Accept-Charset: Specifies the encoding expected in the response.
- Cookie: Specifies a session identifier in the request derived from a cookie.
- Accept-Encoding: Specifies the type of encoding (usually compression) that is expected from the answer. (Not all browsers send this header)
Structure of a POST response
Typical structure of a POST response | Sample | |
HTTP version " state | HTTP-version-state | HTTP/1.1 200 OK |
Date | date-string | Tue, 07 Jun 2011 05:52:31 GMT |
Server | server-string | Apache/2.2.17 (Win32) mod_ssl/2.2.17... |
Expires | expire-date-string | Thu, 19 Nov 1981 08:52:00 GMT |
Cache-Control | Cache-control-string | No-store, no-cache, must-revalidate... |
Pragma | pragma-string | No. |
Content-Length | Content-length-int | 297 |
Content-Type | Content-type-string | text/html |
Keep-Alive | Keep-alive-string | timeout=5, max=98 |
Connection | Connection-string | Keep-Alive |
X-Powered-By | X-powered-by-string | PHP/5.3.5 |
Encoding the request body message
The data that is sent in the body of the POST request must be in some format that allows it to be manipulated in future processing. For this reason, the request must have the Content-Type header assigned, whose value will be the encoding of the data. In this way, the system will be able to differentiate between isolated variables, binary data, plain text, or any other type of format. The format of a data string is called MIME and it is the value that should be included in this header.
In HTML the Content-Type header is automatically specified and its value is application/x-www-form-urlencoded, however two other values can be specified by default: multipart/form -data
and text/plain
using the enctype
attribute of the form
element as follows
|
|
|
Or any other MIME value. The multipart/form-data
is used to send large binary strings that are anything other than plain text, such as images, videos, or executables. For multiple values, separate by commas.
The application/x-www-form-urlencoded
automatically encodes the values of all form elements like variable=value
, separated by &
. The name
attribute of an input is usually the name of the variable and its value
the value. Spaces are replaced by +
and non-alphanumeric characters by $HH
where HH represents the hexadecimal number of the ASCII character.
id=value++la+variable faketama%A4o=4o |
which represented in another way is:
id: variable value size: 4 |
Browser Procedure
The browser collects the information from the form to create the request and send it. The headers are sent along with the POST request, and are collected based on hard-coded metatags, browser autotags, and cookies. It is the browser, too, that encodes the data if necessary. [citation required]
Operation
The web server runs on a computer waiting for requests from a client (a web browser) and responds to these requests appropriately, through a web page that will be displayed in the browser or by displaying the respective message if some error was detected. By way of example, when we type www.wikipedia.org in our browser, it makes an HTTP request to the server for that address. The server responds to the client by sending the HTML code of the page; the client, once the code is received, interprets it and displays it on the screen. As we can see with this example, the client is in charge of interpreting the HTML code, that is, showing the fonts, colors and layout of the texts and objects on the page; the server is only limited to transferring the code of the page without carrying out any interpretation of it.
In addition to the transfer of HTML code, web servers can deliver web applications. These are pieces of code that are executed when certain HTTP requests or responses are made. You have to distinguish between:
- Applications on the client side: the web client is responsible for running them on the user's machine. They are the Java "applets" or Javascript applications: the server provides the code of the applications to the client and this, using the browser, executes them. It is therefore necessary for the client to have a browser capable of running applications (also called scripts). Usually, browsers allow to run written applications in language Javascript and Java, although more languages can be added by using plugins.
- Applications on the server side: the web server executes the application; this, once executed, generates a certain HTML code; the server takes this newly created code and sends it to the client through the HTTP protocol.
Server applications are often the best option for building web applications. The reason is that, since it is executed on the server and not on the client's machine, the latter does not need any added capacity, as it does in the case of wanting to run Javascript or Java applications. Thus, any client with a basic web browser can use these types of applications.
The fact that HTTP and HTML are closely linked should not lead to confusion between the two terms. HTML is a markup language and HTTP is a "protocol".
Server-side application
A server-side application is any program or set of instructions designed to be processed by a web server to perform some action. Server-side applications are written using some programming language, among which are:
Language | Date of first stable version | Operating system | Latest stable version |
PHP | 1995 | Multiplatform | 8.1.8 |
ASP | 1998 | Windows (Some versions) | 4.0 |
Perl | 1987 | Multiplatform | 5.36.0 |
Python | 1991 | Multiplatform | 3.10.5 |
Ruby | 1995 | Multiplatform | 3.1.0 |
75% of server-side applications are written in PHP, followed by ASP and the other options used alternately and very casually.
Server-side processing
A web server has the function of processing server-side scripts to output HTML and other client-side languages to the client's web browser. The information to be processed may be transferred by the client to the script through any application in the browser environment. This can be done by using web forms, links with the implicit values in the string, or any other method.
PHP Processing
In PHP there are global variables that represent variables and data of the connections that the server establishes with the client.
GET method
Contains all variables that are sent via the HTTP GET method, referenced via the one-dimensional array $_GET['variable']
. This variable contains the data sent by GET associated with that variable, if it exists.
POST method
Contains all variables that are sent via the HTTP POST method, referenced via the one-dimensional array $_POST['variable']
. This variable contains the data sent by POST associated with that variable.
Sessions
Contains session data acquired through a GET, POST request, or reading a cookie.[citation needed] Referenced via the one-dimensional array $ _SESSION['variable']
. This variable contains session data.
Cookies
Contains data about all cookies acquired in the request to the server, provided by the browser in the HTTP request. It is referenced via the one-dimensional array $_COOKIES['variable']
.
Server
Contains data provided by the web server. It is referenced via the one-dimensional array $_SERVER['variable']
.
Processing
1) Given the following PHP code:
In the above case, the user's decision could be taken for granted by using a link whose destination is the file containing the above script + the variable and the value using the following syntax: file.php?var=val
where var
is the name of a given variable and val
is the value assigned to the variable.
http://ruta/archivo.php?ip=yes
2) If so, the above script generates the following HTML code that is subsequently sent to the browser:
.b▪Your web address is 192.168.0.1 ”b▪
3) The browser interprets the HTML code (PHP always returns HTML to the browser) and displays it similar to:
Their web address is 192.168.0.1
Local web server
A local web server is a web server that resides on a network local to the reference computer. The local web server can be installed on any of the computers that are part of a local network. It is therefore obvious that all web servers are local to the local network in which they are located, or at least local to the system in which they are installed.
When a web server is installed on the same computer from which you want to access it, you can use the Loopback address, 127.0.0.1
in IPv4 and ::1
in IPv6. TCP port 80 is ignored. The files are stored in a directory determined by the configuration, usually writable.
There are numerous applications that facilitate the automatic installation of Apache web servers and additional applications such as Mysql and PHP (among others), together, such as XAMPP, JAMP or EasyPHP. These applications are called LAMP when installed on Linux platforms, WAMP on Windows systems, and MAMP on Apple Macintosh systems.
Software
Some important web servers are:
- Nginx
- Apache
- Internet Information Services (IIS)
- Cherokee
- Tomcat
Other servers, simpler but faster, are:
- lighttpd
- thttpd
Contenido relacionado
Electroacoustics
Submarine
Modulated amplitude