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 can I set attribute to request object in FastAPI from middleware?

How can I set an arbitrary attribute to the Request object from the middleware function? from fastapi import FastAPI, Request app = FastAPI() @app.middleware("http") async def set_custom_attr(request: Request, call_next): request.custom_attr…
JPG
  • 82,442
  • 19
  • 127
  • 206
10
votes
7 answers

Get starlette request body in the middleware context

I have such middleware class RequestContext(BaseHTTPMiddleware): async def dispatch(self, request: Request, call_next: RequestResponseEndpoint): request_id = request_ctx.set(str(uuid4())) # generate uuid to request body = await…
sashaaero
  • 2,618
  • 5
  • 23
  • 41
10
votes
2 answers

What does 'return $next($request)' do in Laravel middleware?

Please respect that I'm new to programming and Laravel, so this question might seem a little odd to the most of you. But I think this is what stackoverflow is for, so: When I created a new middleware with the command php artisan make:middleware…
ofmiceandmoon
  • 548
  • 2
  • 9
  • 30
10
votes
2 answers

Getting empty response on ASP.NET Core middleware on exception

I am trying to create a middleware that can log the response body as well as manage exception globally and I was succeeded about that. My problem is that the custom message that I put on exception it's not showing on the response. Middleware Code…
Muhammad Azim
  • 329
  • 1
  • 2
  • 14
10
votes
1 answer

Rails - how can I make a request that doesn't hit the database at all?

In order to trace some performance issues, I'm trying to create a page that is rendered through the Rails (2.3.8) framework but makes no calls whatsoever to the database. I want the request to go through the typical middleware (routes.rb >…
sa125
  • 28,121
  • 38
  • 111
  • 153
10
votes
3 answers

Redux middleware design re: return values

So I've just read up on redux middleware, and it sounds great. One thing is bugging me though - the return values of the middleware. I understand that some instances of middleware return stuff (i.e. redux-promise) , and I get that other middleware…
maambmb
  • 881
  • 1
  • 8
  • 18
10
votes
3 answers

How can I share session among subdomains in ASP.NET Core?

I have a website which has subdomains such as ali.sarahah.com but if a user logs in from www.sarahah.com then goes to ali.sarahah.com the session is not saved. After searching I added the following in Startup.cs: app.UseCookieAuthentication(new…
Techy
  • 2,026
  • 4
  • 20
  • 41
10
votes
3 answers

Laravel 5.2.x disable specific middleware

Is it possible to disable a specific middleware without disabling all middleware? I will use it when running tests, so I don't want to define middleware groups and then assign them to my routes. $this->withoutMiddleware(); // <-- This will prevent…
aleixfabra
  • 1,075
  • 3
  • 11
  • 24
10
votes
2 answers

Expressjs router based on Content-Type header

For routing, I'd like my middleware to pass the request the routes defined in a /html folder to server HTML(ejs), and if header Content-Type is application/json, use the routes defined in the /api folder. But I don't want to have to define that in…
CherryNerd
  • 1,258
  • 1
  • 16
  • 38
10
votes
3 answers

How can I get Guzzle 6 to retry a request upon a 503 error in Laravel

I've written some code in Laravel 5.2 to retrieve results from an unrelible API source. However, it needs to be able to automatically retry the request on failed attempts, as the API call results in a 503 about a third of the time. I'm use Guzzle to…
ZeroGodForce
  • 143
  • 1
  • 2
  • 6
10
votes
1 answer

Rails 5 Upgrade: No such middleware to insert after: ActionDispatch::ParamsParser (RuntimeError)

I am upgrading an app from Rails 4.2 to Rails 5 beta1.1 in development. App worked well before upgrade. I have gone through the basic upgrade steps (updating Ruby, updating Rails, and related steps…
TH1J2
  • 223
  • 2
  • 11
10
votes
2 answers

App Engine (python) skips webapp middleware (like Appstats) in production but works fine on dev server

I'm using App Engine python to host an application and would love to use Appstats and a couple of other libraries that run as middleware. However, when I set up middleware through appengine_config.py (as shown below) it works on the dev server but…
10
votes
3 answers

Is it advisable to bind application data to request in Laravel 5

Would it be advisable, if i am doing authentication in a middleware and adding some data to the \Illuminate\Http\Request $request object and using that data in the controller by injecting \Illuminate\Http\Request $request into the controller…
Swaraj Giri
  • 4,007
  • 2
  • 27
  • 44
10
votes
3 answers

What is the correct way to trigger OWIN cookie middleware set to passive authentication mode?

I have been following the OAuth 2.0 Authorization Server sample code http://www.asp.net/aspnet/overview/owin-and-katana/owin-oauth-20-authorization-server As well as looking at the nugget package Microsoft.aspnet.identity.samples…
Steve
  • 596
  • 2
  • 7
  • 20
10
votes
4 answers

npm express "hello world" middleware error

node --version v0.10.26 npm --version 1.4.3 I followed this: http://expressjs.com/guide.html which has this code var express = require('express'), app = express(); app.use(express.logger()); app.get('/', function(req, res){ …
user3543240
  • 133
  • 1
  • 2
  • 6