Giter Club home page Giter Club logo

Comments (6)

Tobion avatar Tobion commented on May 1, 2024

Hey @vicb, long time no see. How are you doing?

I don't see how you want to improve setHeaders actually. withAddedHeader and withHeader keep immutability. And setHeaders doesn't and it is basically only used in the constructor. Can you create a PR with what you had in mind?

from psr7.

vicb avatar vicb commented on May 1, 2024

@Tobion I'm doing very, working on the client side ATM - happy to hear about / see some of the PHP community members from time to time.

I mean SetHeaders should not concat but "Set" the header

So something along the line

    public function withHeader($header, $value)
    {
        return $this->withHeaderClone($header, $value, /* clone */ true);
    }

    private function setHeaders(array $headers)
    {
        foreach ($headers as $header => $value) {
            $this->withHeaderClone($header, $value, /* clone */ false);
        }
    }

An other thing I notice (actually why I look at the code first) is that:

// sends Content-Type: b
->withHeader('content-type', 'a')
->withHeader('Content-Type', 'b')

// sends content-type: b
->withHeader('Content-Type', 'a')
->withHeader('content-type', 'b')

It seems weird to me that we use the last name - and the spec is not deterministic on this point.
why the last, why not the first ?

I was looking at node.js and it seems that it normalizes the names

/ref angular/angular#11624

from psr7.

Tobion avatar Tobion commented on May 1, 2024

A possible refactoring would always mean to introduce more methods to the trait, which makes it slightly slower and adds more extension points that need to be maintainted (because you cannot hide methods in a trait). I think that is way worse than a few lines of duplicated code.

It seems weird to me that we use the last name - and the spec is not deterministic on this point.

True, AFAIK it's not clearly specified. But I think it makes more sense the way it is. There might a use-case to actually change the header case because of legacy clients or whatever. So this allows to do that. If you really need to keep the original case is kinda strange because that would mean you rely on the fact that the header has been specified before at all. So either you care about the header case, then you write it the way you want. Or you don't care (because it shouldn't matter), then you also do not care what the case was before.

from psr7.

vicb avatar vicb commented on May 1, 2024

A possible refactoring would always mean to introduce more methods to the trait, which makes it slightly slower and adds more extension points that need to be maintainted (because you cannot hide methods in a trait). I think that is way worse than a few lines of duplicated code.

Couldn't you call a function outside of the trait (oh... long time no PHP...)

But I think it makes more sense the way it is

The original bug report on Angular could be triggered with

->withHeader('authorization', 'b') // Apache will ignore this

so I think normalization is slighty less worse...

from psr7.

Tobion avatar Tobion commented on May 1, 2024

Well, automatic normalization is a completely different topic and definitely not implied in PSR-7.

Couldn't you call a function outside of the trait

That would be an extension point as well.

from psr7.

vicb avatar vicb commented on May 1, 2024

Makes sense, closing then.

from psr7.

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.