Skip to content

Set a default header #408

Open
Open

Description

@Suebersson

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

Activity

  1. kevmoo commented on Feb 8, 2024

    @kevmoo
    Member

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

    Maybe as a zone variable?

  2. Suebersson commented on Feb 8, 2024

    @Suebersson
    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

  3. Suebersson commented on Feb 8, 2024

    @Suebersson
    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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions