Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set a default header #408

Open
Suebersson opened this issue Feb 6, 2024 · 3 comments
Open

Set a default header #408

Suebersson opened this issue Feb 6, 2024 · 3 comments
Labels
package:shelf type-enhancement A request for a change that isn't a bug

Comments

@Suebersson
Copy link

Hello, I would like to implement a variable
[static Map<String, Object> defaultHeaders] from within the [Response] class to define an instance of default [headers] for all [Response] of the web server app. If possible, this will make developers' lives much easier without having to create [Middleware] to intercept, process and add the standard header to each requested response.

Thank you in advance, Suebersson.

How would this look:

Olá, eu gostaria que fosso implementado uma variável
[static Map<String, Object> defaultHeaders] de dentro da classe [Response] para definirmos uma instância de [headers] padrão da para todas as [Response] do app web server. Sendo possível, isso irá facilitar muito a vida dos desenvolvedores sem precisar ter que criar uma [Middleware] para interceptar, processar e adicionar a header padrão dentro cada response de requisitada.

Desde já agradeço, Suebersson.

Como isso isso ficaria:

class Response extends Message {

  static Map<String, Object>? defaultHeaders;

  Response(
    this.statusCode, {
    Object? body,
    Map<String, Object>? headers,
    Encoding? encoding,
    Map<String, Object>? context,
  }) : super(body, encoding: encoding, headers: headers ?? defaultHeaders, context: context) {
    if (statusCode < 100) {
      throw ArgumentError('Invalid status code: $statusCode.');
    }
  }

}

Captura de tela 2024-02-05 225403

@kevmoo
Copy link
Member

kevmoo commented Feb 8, 2024

Probably not as a top-level static. So many anti-patterns there.

Maybe as a zone variable?

@kevmoo kevmoo added the type-enhancement A request for a change that isn't a bug label Feb 8, 2024
@Suebersson
Copy link
Author

Probably not as a top-level static. So many anti-patterns there.

Maybe as a zone variable?

It may even be an anti-pattern, but I saw that using the responder.change(...) constructor creates a new instance, reprocessing everything again, reprocessing all internal methods again. This can be avoided if we could define the app's default response header, even if this is done through a variable

@Suebersson
Copy link
Author

Probably not as a top-level static. So many anti-patterns there.

Maybe as a zone variable?

I'm sorry, I researched "zone" and didn't find anything that could define the default header in the web server app with shelf

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
package:shelf type-enhancement A request for a change that isn't a bug
Projects
None yet
Development

No branches or pull requests

2 participants