Coder Social home page Coder Social logo

Problem with headersForQuery about brick HOT 4 CLOSED

getdutchie avatar getdutchie commented on July 17, 2024 2
Problem with headersForQuery

from brick.

Comments (4)

polRk avatar polRk commented on July 17, 2024

It's little fix.

  • Save old headers;
  • Add new headers;
  • Send request
  • Wait response
  • Remove new headers
  • Return response
  Future<http.StreamedResponse> send(http.BaseRequest request) async {
    final token = await _tokenRepository.getIdToken();

    request.headers['Authorization'] = 'Bearer $token';
    
    final response = await _inner.send(request);
    request.headers.remove('Authorization');
    
    return response;
  }

from brick.

polRk avatar polRk commented on July 17, 2024

But if you want to use providerArgs with custom httpClient, you should add

final defaultHeaders = <String, String>{
  'Content-Type': 'application/json; charset=utf-8'
};

final providerArgs = <String, dynamic>{
  'request': 'PUT',
  ...defaultHeaders,
};

...

restProvider: RestProvider(client: client)..defaultHeaders = defaultHeaders,

from brick.

tshedor avatar tshedor commented on July 17, 2024

Thanks @polRk for helping out with this one!

@pkozlovskiy Are you subclassing RequestSqliteCache? It sounds like you might be if you're mutating the headers on subsequent retries.

In this use case, I would instead recommend implements over extends so that you're not storing the headers or making SQLite queries based on the headers.

I hadn't anticipated this sort of usage, so my other suggestion is to open a PR and make _findRequestInDatabase a @visibleForOverriding method. That way, you'll be able to ignore the headers column (since these change) in subsequent lookups and you'll be able to extends RequestSqliteCache without rewriting a lot of the functionality. I also think making headersForQuery a method that's @visibleForOverriding instead of @protected would be useful.

from brick.

tshedor avatar tshedor commented on July 17, 2024

@pkozlovskiy With #122 merged I'm going to close, please reopen if you're still having trouble

from brick.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.