bg_image
header

Bearer Token

A Bearer Token is a type of access token used for authentication and authorization in web applications and APIs. The term "Bearer" means "holder," which implies that anyone in possession of the token can access protected resources—without additional verification.

Characteristics of a Bearer Token:

  • Self-contained: It includes all necessary authentication information.
  • No additional identity check: Whoever holds the token can use it.
  • Sent in HTTP headers: Typically as Authorization: Bearer <token>.
  • Often time-limited: Tokens have expiration times to reduce misuse.
  • Commonly used with OAuth 2.0: For example, when authenticating with third-party services.

Example of an HTTP request with a Bearer Token:

GET /protected-data HTTP/1.1
Host: api.example.com
Authorization: Bearer abcdef123456

Risks:

  • No protection if stolen: If someone intercepts the token, they can impersonate the user.
  • Must be securely stored: Should not be exposed in client-side code or URLs.

💡 Tip: To enhance security, use short-lived tokens and transmit them only over HTTPS.

 

 


Entity Header

Entity headers are HTTP headers that provide information about the body of a message. They can appear in both requests and responses, describing properties of the content such as type, length, encoding, or last modification date.

Important Entity Headers:

1. Content-Type

  • Specifies the media type (MIME type) of the content.
  • Example:
Content-Type: application/json; charset=UTF-8

2. Content-Length

  • Indicates the size of the content in bytes.
  • Example:
Content-Length: 1024

3. Content-Encoding

  • Shows if the content has been compressed (e.g., gzip).
  • Example:
Content-Encoding: gzip

4. Content-Language

  • Specifies the language of the content.
  • Example:
Content-Language: de-DE

5. Cache-Location

  • Indicates the URL or storage location of the actual resource.
  • Example:
Content-Location: /files/document.pdf

6. Last-Modified

  • Specifies when the content was last changed.
  • Example:
Last-Modified: Tue, 30 Jan 2025 14:20:00 GMT

7. ETag

  • A unique identifier for a version of the resource, useful for caching.
  • Example:
ETag: "abc123xyz"

8. Expires

  • Indicates when the content should be considered outdated.
  • Example:
Expires: Fri, 02 Feb 2025 12:00:00 GMT

9. Allow

  • Lists the allowed HTTP methods for a resource.
  • Example:
Allow: GET, POST, HEAD

10. Refresh  (Not standardized but often used)

  • Instructs the browser to refresh the page after a specified time.
  • Example:
Refresh: 10; url=https://example.com

These headers help describe the content of an HTTP message, optimize caching strategies, and ensure correct rendering.




Response Headers

Response headers are HTTP headers sent from the server to the client. They contain information about the server’s response, such as status codes, content types, security policies, or caching rules.

Important Response Headers:

1. Server

  • Indicates which software or technology the server is using.
  • Example:
Server: Apache/2.4.41 (Ubuntu)

2. Date

  • Specifies the date and time of the server’s response in GMT format.
  • Example:
Date: Wed, 31 Jan 2025 12:34:56 GMT

3. Content-Type

  • Defines the media type of the response.
  • Example:
Content-Type: text/html; charset=UTF-8

4. Content-Length

  • Indicates the size of the response in bytes.
  • Example:
Content-Length: 3456

5. Cache-Control

  • Determines the caching behavior of the response.
  • Example:
Cache-Control: max-age=3600, must-revalidate

6. Set-Cookie

  • Sends cookies to the client for storage and future requests.
  • Example:
Set-Cookie: sessionId=abc123; Path=/; Secure; HttpOnly

7. ETag

  • A unique identifier for a specific version of a resource, used for caching optimization.
  • Example:
ETag: "5d8c72a5f8d9f"

8. Location

  • Specifies a redirect URL if a resource has moved.
  • Example:
Location: https://www.new-url.com/

9. Access-Control-Allow-Origin

  • Enables cross-origin requests (CORS).
  • Example:
Access-Control-Allow-Origin: *

10. Strict-Transport-Security (HSTS)

  • Enforces HTTPS for future requests.
  • Example:
Strict-Transport-Security: max-age=31536000; includeSubDomains

Response headers help the client interpret the received response correctly, enforce security measures, and optimize caching strategies.


HTTP Request headers

Request headers are HTTP headers sent by a client (e.g., a web browser or API request) to the server, providing additional information about the request, the client, or the desired content.

Important Request Headers:

1. Host

  • Specifies the target domain or IP address of the server.
  • Example:
Host: www.example.com

2. User-Agent

  • Contains information about the client, such as browser type or operating system.
  • Example:
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64)

3. Accept

  • Defines which content types the client can accept.
  • Example:
Accept: text/html, application/json

4. Accept-Language

  • Specifies the client's preferred language(s).
  • Example:
Accept-Language: de-DE, en-US

5. Accept-Encoding

  • Indicates which compression formats the client supports.
  • Example:
Accept-Encoding: gzip, deflate, br

6. Referer

  • Provides the previous page from which the user navigated.
  • Example:
Referer: https://www.google.com/

7. Authorization

  • Used for authentication when accessing protected resources.
  • Example(Basic Auth):
Authorization: Basic dXNlcm5hbWU6cGFzc3dvcmQ=

8. Cookie

  • Contains cookies previously set by the server.
  • Example:
Cookie: sessionId=abc123; theme=dark

9. Content-Type (for POST/PUT-Anfragen)

  • Specifies the data format of the request body.
  • Example:
Content-Type: application/json

10. Origin

  • Indicates the origin URL and is often used in Cross-Origin requests.
  • Example:
Origin: https://www.example.com

These headers help the server understand the request and respond accordingly by providing details about the client, preferred content, and security aspects.


General HTTP headers

General HTTP headers are headers that can be used in both HTTP requests and responses. They contain general information about the connection and data transfer that is not specific to the client, server, or content.

Wichtige allgemeine Header:

1. Cache-Control

  • Controls caching behavior for clients or proxy servers.
  • Example:
Cache-Control: no-cache, no-store, must-revalidate

2. Connection

  • Defines whether the connection should remain open after the request.
  • Example:
Connection: keep-alive

3. Date

  • Contains the date and time of the HTTP message in GMT format.
  • Example:
Date: Wed, 31 Jan 2025 12:34:56 GMT

4. Pragma (veraltet, aber noch genutzt)

  • Similar to Cache-Control, mainly used for backward-compatible caching rules.für rückwärtskompatible Caching-Regeln genutzt.
  • Example:
Pragma: no-cache

5. Trailer

  • Specifies which headers will be sent after the message body.
  • Example:
Trailer: Expires

6. Transfer-Encoding

  • Specifies how the message body is transferred, e.g., in chunks.
  • Example:
Transfer-Encoding: chunked

7. Upgrade

  • Used to upgrade the connection to a different protocol, such as WebSockets.
  • Example:
Upgrade: websocket

8. Via

  • Indicates through which proxies or gateways the message was routed.
  • Example:
Via: 1.1 proxy.example.com

These headers improve communication between the client and server, manage caching, and allow protocol upgrades.


HTTP Header

HTTP headers are metadata exchanged between the client (e.g., a browser) and the server during HTTP requests and responses. They contain important information for communication, such as:

  1. General headers – Apply to both requests and responses (e.g., Cache-Control for caching rules).
  2. Request headers – Provide details about the client's request (e.g., User-Agent, which identifies the browser type).
  3. Response headers – Contain information about the server's response (e.g., Server, which indicates the web server used).
  4. Entity headers – Describe the content of the message (e.g., Content-Type, which specifies the media type of the response).

Example of an HTTP request with headers:

GET /index.html HTTP/1.1
Host: www.example.com
User-Agent: Mozilla/5.0
Accept: text/html

Example of an HTTP response with headers:

HTTP/1.1 200 OK
Content-Type: text/html
Content-Length: 3456
Server: Apache

HTTP headers are commonly used for security (e.g., Strict-Transport-Security), performance optimization (e.g., Cache-Control), and authentication (e.g., Authorization).

 

 

 


CORS - Cross Origin Resource Sharing

CORS (Cross-Origin Resource Sharing) is a security mechanism implemented by web browsers to control which websites can access resources from other domains. By default, browsers block cross-origin requests—requests made from one website to another domain, protocol, or port—for security reasons.

Why does CORS exist?

Without CORS, malicious websites could secretly send requests to other servers (e.g., API servers or banking sites), potentially stealing or misusing sensitive data (Cross-Site Request Forgery, CSRF). CORS ensures that only explicitly allowed websites can access resources.

How does CORS work?

When a web application makes a cross-origin request (e.g., from http://example.com to https://api.example.com), the browser automatically sends a CORS request. The server must then respond with specific HTTP headers to indicate whether the request is allowed:

  1. Without CORS headers:
    The browser blocks the request.

  2. With CORS headers:
    The server can respond with Access-Control-Allow-Origin: * (allowing all domains) or a specific domain (Access-Control-Allow-Origin: https://example.com). This enables access.

Preflight Requests

For certain requests (e.g., PUT, DELETE, or requests with custom headers), the browser sends a preflight request using the OPTIONS method. The server must respond with the correct CORS headers to allow the main request.

Conclusion

CORS is a crucial security measure that prevents unauthorized websites from accessing foreign resources. Developers must configure the correct server-side headers to allow legitimate clients to access the data.

 


Iris

The Iris Framework is a modern, high-performance web framework for the Go (Golang) programming language. It’s commonly used to build web applications, APIs, and microservices. Iris focuses on speed, flexibility, and ease of use, providing a variety of features to streamline development.

Key Features of Iris:

  1. High Performance:

    • Iris is one of the fastest web frameworks for Go, optimizing network traffic and memory management for fast HTTP request handling.
  2. Ease of Use:

    • It offers an intuitive API, making it beginner-friendly, even for developers new to Go.
  3. Feature-Rich:

    • Supports the MVC architecture.
    • Built-in middleware like authentication, logging, and CORS.
    • WebSocket support for real-time applications.
    • Internationalization (i18n) for multilingual apps.
    • Built-in support for template engines such as HTML, Handlebars, Pug, and more.
  4. Extensibility:

    • Allows integration with third-party libraries and plugins, making it adaptable for diverse project needs.
  5. Flexible Routing:

    • Includes support for wildcards, parameters, and custom middleware for complex URL structures.
  6. File Server and WebSockets:

    • Enables serving static files and implementing WebSocket communication.
  7. Developer-Friendly:

    • Includes tools like hot reloading for faster development cycles.
    • Supports modern Go module management.

Use Cases:

  • Building RESTful APIs
  • Developing web applications (e.g., single-page apps, admin dashboards)
  • Creating microservices
  • Real-time applications like chat systems or notification platforms

Why Use Iris?

Iris is particularly suitable for developers looking for a fast and reliable solution to build web applications. It combines Go's speed with a developer-friendly API, saving time and effort.

Resources:

 


LAMP Stack

The LAMP stack is a collection of open-source software used together to develop dynamic websites and web applications. The acronym LAMP stands for the following components:

  1. LLinux

    • The operating system on which the server runs.
    • Linux is known for its stability, security, and flexibility, making it a popular choice for web servers.
  2. AApache

    • The web server that handles HTTP requests and delivers web pages.
    • Apache is renowned for its reliability, modularity, and extensive configuration options.
  3. MMySQL (or MariaDB)

    • The database management system responsible for storing and managing data.
    • MySQL stores data such as user information, content, or transaction records.
  4. PPHP, Perl, or Python

    • The programming language used to develop dynamic content and functionality.
    • PHP is the most commonly used language for implementing server-side logic.

Advantages of the LAMP Stack:

  • Open Source: All components are freely available.
  • Flexibility: Supports a wide range of applications and workflows.
  • Community Support: Widely used, so there are plenty of tutorials, documentation, and support forums.
  • Stability: A proven and reliable solution that has been established for many years.

Fun Fact:

The LAMP stack is often compared to modern alternatives like the MEAN stack (MongoDB, Express.js, Angular, Node.js), but it remains popular due to its simplicity and reliability, especially for traditional web development projects.

 


PSR-7

PSR-7 is a PHP Standard Recommendation (PSR) that focuses on HTTP messages in PHP. It was developed by the PHP-FIG (Framework Interoperability Group) and defines interfaces for working with HTTP messages, as used by web servers and clients.

Key Features of PSR-7:

  1. Request and Response:
    PSR-7 standardizes how HTTP requests and responses are represented in PHP. It provides interfaces for:

    • RequestInterface: Represents HTTP requests.
    • ResponseInterface: Represents HTTP responses.
  2. Immutability:
    All objects are immutable, meaning that any modification to an HTTP object creates a new object rather than altering the existing one. This improves predictability and makes debugging easier.

  3. Streams:
    PSR-7 uses stream objects to handle HTTP message bodies. The StreamInterface defines methods for interacting with streams (e.g., read(), write(), seek()).

  4. ServerRequest:
    The ServerRequestInterface extends the RequestInterface to handle additional data such as cookies, server parameters, and uploaded files.

  5. Middleware Compatibility:
    PSR-7 serves as the foundation for middleware architectures in PHP. It simplifies the creation of middleware components that process HTTP requests and manipulate responses.

Usage:

PSR-7 is widely used in modern PHP frameworks and libraries, including:

Purpose:

The goal of PSR-7 is to improve interoperability between different PHP libraries and frameworks by defining a common standard for HTTP messages.