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
20
votes
2 answers

How to write a custom FastAPI middleware class

I have read FastAPI's documentation about middlewares (specifically, the middleware tutorial, the CORS middleware section and the advanced middleware guide), but couldn't find a concrete example of how to write a middleware class which you can add…
Dean Gurvitz
  • 854
  • 1
  • 10
  • 24
20
votes
6 answers

Laravel middleware returning (Trying to get property 'headers' of non-object) error

I'm getting error when I wrap a resource route to my custom middleware My middleware:
MorshedSaif
  • 399
  • 1
  • 2
  • 9
20
votes
2 answers

django middleware difference between process_request and process_view

I am little bit confused on process_request and process_view. Process request is something that u want to pass on view with request. Example can be taken from request.user. Then what does process_view does ? Is it for executing any view initially…
varad
  • 7,309
  • 20
  • 60
  • 112
19
votes
2 answers

How do I use a Rack middleware only for certain paths?

I'd like to have MyMiddleware run in my Rack app, but only for certain paths. I was hoping to use Rack::Builder or at least Rack::URLMap, but I can't quite figure out how. This is what I thought would work, but doesn't: # in my rackup file or Rails…
James A. Rosen
  • 64,193
  • 61
  • 179
  • 261
19
votes
5 answers

How to read request body multiple times in asp net core 2.2 middleware?

I tried this: Read request body twice and this: https://github.com/aspnet/Mvc/issues/4962 but did not work. I read request body like this: app.Use(async (context, next) => { var requestBody = await ReadStream(context.Request.Body); var…
Alireza Yavari
  • 309
  • 1
  • 2
  • 9
19
votes
2 answers

ASP.NET Core Response.End()?

I am trying to write a piece of middleware to keep certain client routes from being processed on the server. I looked at a lot of custom middleware classes that would short-circuit the response with context.Response.End(); I do not see the End()…
Michael W Riemer Jr
  • 531
  • 2
  • 8
  • 16
19
votes
4 answers

Laravel Dependency Injection in Middleware

I am using Laravel-5.0's default Authentication Middleware, but I changed the signature of the handle function to have: public function handle($request, Closure $next, AuthClientInterface $authClient) I also registered AuthClientInterface in a…
ajon
  • 7,868
  • 11
  • 48
  • 86
19
votes
5 answers

Parsing Post Form Data Node.js Express

I am getting form data in this form '------WebKitFormBoundarysw7YYuBGKjAewMhe\r\nContent-Disposition: form-data; name': '"a"\r\n\r\nb\r\n------WebKitFormBoundarysw7YYuBGKjAewMhe--\r\n I'm trying to find a middleware that will allow me to access…
Dan Baker
  • 1,757
  • 3
  • 21
  • 36
19
votes
1 answer

Middleware design pattern in Node.js: Connect

This question extends that of What is Node.js' Connect, Express and "middleware"? I'm going the route of learning Javascript -> Node.js -> Connect -> Express -> ... in order to learn about using a modern web development stack. I have a background in…
gone
  • 2,587
  • 6
  • 25
  • 32
18
votes
1 answer

Rails 3 middleware modify request headers

My setup: Rails 3.0.9, Ruby 1.9.2 I am working on my first middleware app and it seems like all of the examples deal with modify the response. I need to examine and modify the request headers in particular, delete some offending headers that cause a…
Bob
  • 8,424
  • 17
  • 72
  • 110
18
votes
1 answer

How can I return a response in ASP.NET Core MVC middleware using MVC's content negotiation?

I have some ASP.NET Core MVC middleware to catch unhandled exceptions that I would like to return a response from. While it is easy to just httpContext.Response.WriteAsync to write a string and e.g. use JsonSerializer to serialise an object to a…
Joseph Earl
  • 23,351
  • 11
  • 76
  • 89
18
votes
4 answers

Unit test Laravel middleware

I am trying to write unit tests for my middleware in Laravel. Does anyone know a tutorial, or have an example of this ? I have been writing a lot of code, but there must be a better way to test the handle method.
Nealv
  • 6,856
  • 8
  • 58
  • 89
18
votes
1 answer

How to proper log every exception using OWIN

my question should be quite simple, but unfortunately I had no luck in solving it. Basically, I have some Web API controllers hosted by OWIN and deployed on Azure. I really need to track down exceptions that occur in each middleware (for example…
Menion Leah
  • 341
  • 2
  • 11
17
votes
3 answers

How to run setSubmitting() outside the submit handler?

I'm trying to implement the approach described on https://www.youtube.com/watch?v=5gl3cCB_26M, where all Redux actions are just plain objects (as they were meant to be) and API calls are done by middlewares. By doing this, the dispatched actions…
Matheus Gomes
  • 173
  • 1
  • 1
  • 4
17
votes
1 answer

Laravel 5 - Defining middleware for multiple routes in controller file

Stackers! I'm currently learning laravel5 and I love it, but I'm struggling with one thing. Since Laravel 5 we have Middleware which we can use in controller's construct function, like this: Controller file: public function __construct() { …
Talky
  • 173
  • 1
  • 4