leafsphp / http

📡 Leaf Http module
https://leafphp.dev/modules/http/
7 stars 9 forks source link

add custom responses (fix #21) #22

Closed Rasalas closed 1 week ago

Rasalas commented 1 week ago

What kind of change does this PR introduce? (pls check at least one)

Description

As described in #21 there was no way to create custom Content-Type responses. (I needed it for a js response)

I added

    /**
     * Output any text
     * 
     * @param string $data The data to output
     * @param int $code The response status code
     */
    public function echo(string $data, int $code = 200)
    {
        $this->status = $code;
        $this->headers['Content-Type'] ??= 'text/plain';
        $this->content = $data;

        $this->send();
    }

to add custom content type functionality with a fallback to text/plain

Then I added a "js()" function with Content-Type of text/javascript to fit my exact need (might not be super common).

Does this PR introduce a breaking change? (check one)

Related Issue

21

mychidarko commented 1 week ago

Thanks for the PR @Rasalas