Questions tagged [middleware]

Middleware is computer software that provides services to software applications beyond those available from the operating system. It can be described as "software glue".

Middleware is a software component (or components) that sits "in the middle" between applications and the operating system. Typically, middleware will facilitate application development by providing services such as communications, file access, or thread locking that have a common Application Programming Interface (API) across multiple operating systems.

Communications Middleware is a specific kind of middleware that allows for interprocess communications (on one machine or across a network). The purpose of Communications Middleware is to simplify the designing, programming, and managing of software applications by streamlining the way these applications receive and process data. Communications Middleware simplifies writing communications software while providing sophisticated built-in features, reducing development costs.

Examples of communications middleware include:

4333 questions
10
votes
1 answer

How to hook after `res.send` but before the response leaves the server, ==> when res.statusCode is know

I already use the middleware facility in Express.js by means of app.use() to hook on all requests and log a message, but found the fact that res.statusCode is nearly always 200, which I checked is not correct. I presume this is the default value and…
Diosney
  • 10,520
  • 15
  • 66
  • 111
10
votes
1 answer

How to update Django HttpRequest body in Middleware

I have a PUT request and I want to update the values of few of the params in my middleware. I know there is no way to directly access the PUT params, so I'm accessing them via request.body. Once these values have been updated, I need to pass this…
sparknoob
  • 1,266
  • 14
  • 15
10
votes
2 answers

Class reloading stops after uncaught exception in custom middleware

I've written my own middleware to provide an API endpoint to our application. The middleware loads classes that provide the API methods, and routes the request to the appropriate class/method. The classes are loaded dynamically through…
Mark Wubben
  • 3,329
  • 1
  • 19
  • 16
10
votes
2 answers

Symfony2 middleware

I'm looking for a way to create a Django-like middleware for an application on Symfony2. Basically, I need to preprocess every request before it comes to Controllers and postprocess every response after Controllers, but before it comes to user. Any…
gakhov
  • 1,925
  • 4
  • 27
  • 39
10
votes
2 answers

Scope of middleware functions in express.js

I'm learning express.js / node.js and have a good but not excellent understanding of the javascript prototype model. Hence, I'm a bit confused on the way middleware can be stacked in express.js's routing mechanisms. Say we have this code function…
shredding
  • 5,374
  • 3
  • 46
  • 77
9
votes
1 answer

Node.js - Issue with res.redirect in middleware

I'm trying to use a authenticateUser() middleware before loading all of my pages. Instead of including it in each call (as in app.get('/', authenticateUser, function()...)), I tried setting it with app.use(authenticateUser) right before calling…
Varun Singh
  • 1,676
  • 3
  • 18
  • 25
9
votes
2 answers

NextJs middleware: use default runtime instead of Edge runtime

By default, a NextJs middleware is run using the Edge runtime and from what I understand this is because the middleware is meant to be run on the edge network instead of the main server (being run on the edge network reduces the latency so this…
mccuna
  • 471
  • 7
  • 11
9
votes
1 answer

FastAPI - How to get the response body in Middleware

Is there any way to get the response content in a middleware? The following code is a copy from here. @app.middleware("http") async def add_process_time_header(request: Request, call_next): start_time = time.time() response = await…
nickchen
  • 93
  • 1
  • 1
  • 5
9
votes
3 answers

Detect static file request from .NET core middleware

I'm writing some middleware to parse the sub-domain of a given request URL to determine the website theme. I want to ignore static file requests in order to reduce unnecessary database lookups, and I'm wondering if there's a cleaner way to do…
andrewm
  • 2,552
  • 5
  • 33
  • 63
9
votes
3 answers

Gin-Gonic middleware declaration

I'm using Gin-Gonic and I'm creating a custom middleware. See: https://github.com/gin-gonic/gin#custom-middleware Is there a reason why the middlewares in the doc are written as such: func MyMiddleware() gin.HandlerFunc { return func (c…
cHz
  • 103
  • 1
  • 1
  • 6
9
votes
1 answer

Programmatically invoking the ASP.NET Core request pipeline

Question Is there a way to programmatically invoke the ASP.NET Core request pipeline from within my own application, given I have a HTTP verb, the route, headers and body payload? Background There are use-cases where the WebAPI of our ASP.NET Core…
9
votes
1 answer

What does @app.call(env) really do?

I really love to learn how the things work under de hood, specially when it comes to technology. Currently, I'm studying ruby more deeply and trying to use it only with rack in order to understand how rack based frameworks work. At this moment, rack…
Pedro Vinícius
  • 476
  • 6
  • 13
9
votes
1 answer

Why can I not use func literal as custom func type despite matching parameters in golang?

Package google.golang.org/grpc defines type UnaryClientInterceptor as: type UnaryClientInterceptor func(ctx context.Context, method string, req, reply interface{}, cc *ClientConn, invoker UnaryInvoker, opts ...CallOption) error In my code I'd like…
ddrake12
  • 831
  • 11
  • 22
9
votes
3 answers

How to access updated document during mongoose post update middleware?

I'm wondering if there is any reliable/reusable way to access the updated document during a mongoose post update middleware hook. All I seem to have access to is: schema.post('update', function (result) { console.log(this) // Mongoose Query, no…
Jared Reich
  • 247
  • 4
  • 9
9
votes
1 answer

Laravel 5.3: Use auth/middleware on custom error page

The problem When displaying HTTP error pages (404, 500 and so on), I want to keep the standard design of my current project, including header and footer. My project also includes a registration system. When a user is logged in and receives an error…
manniL
  • 7,157
  • 7
  • 46
  • 72