Skip to content

Zeroplex 生活隨筆

軟體開發、伺服器和生活瑣事

小 縮小字型大小。 中 重設字型大小。 大 放大字型大小。

Customize HTTP header in Unit Test on Lumen

Posted on 2022 年 2 月 23 日2022 年 2 月 23 日 By 日落 在〈Customize HTTP header in Unit Test on Lumen〉中有 1 則留言

按照 Lumen 文件,在 unit test 中建立 HTTP request 要呼叫 $this->call(),但沒辦法自訂 header 內容。

細看實作 Laravel\Lumen\Testing\Concerns\MakesHttpRequests::call():

/**
 * Call the given URI and return the Response.
 *
 * @param  string  $method
 * @param  string  $uri
 * @param  array  $parameters
 * @param  array  $cookies
 * @param  array  $files
 * @param  array  $server
 * @param  string  $content
 * @return \Illuminate\Http\Response
 */
public function call($method, $uri, $parameters = [], $cookies = [], $files = [], $server = [], $content = null)
{
    $this->currentUri = $this->prepareUrlForRequest($uri);

    $symfonyRequest = SymfonyRequest::create(
        $this->currentUri, $method, $parameters,
        $cookies, $files, $server, $content
    );

    $this->app['request'] = LumenRequest::createFromBase($symfonyRequest);

    return $this->response = TestResponse::fromBaseResponse(
        $this->app->prepareResponse($this->app->handle($this->app['request']))
    );
}

從 function parameter 和 return,大概就知道使用這個方法沒辦法塞 header 值。

但是若透過 SymfonyRequest 的話,則可以設定 header 內容:

$request = SymfonyRequest::create();
$request->headers->set('acccess_token', 'ooxx');

因此,若需要自訂 header,則必須 override 原本的 call() 方法。以下是自己改寫的 trait:

use Illuminate\Testing\TestResponse;
use Symfony\Component\HttpFoundation\Request as SymfonyRequest;

trait ApiTokenRequestTrait
{
    public function call($method, $uri, $parameters = [], $cookies = [], $files = [], $server = [], $content = null, $headers = [])
    {
        $symfonyRequest = SymfonyRequest::create(
            $uri,
            $method,
            $parameters,
            $cookies,
            $files,
            $server,
            $content
        );

        foreach ($headers as $key => $value) {
            $symfonyRequest->headers->set($key, $value);
        }

        $this->app['request'] = \Laravel\Lumen\Http\Request::createFromBase($symfonyRequest);

        return TestResponse::fromBaseResponse(
            $this->app->prepareResponse($this->app->handle($this->app['request']))
        );
    }
}
Tags:Laravel, Lumen, PHP

Automatically mount tmpfs on Linux

Posted on 2022 年 2 月 22 日2022 年 2 月 22 日 By 日落 在〈Automatically mount tmpfs on Linux〉中尚無留言

編輯 /etc/fstab,建立新的一行設定:

tmpfs    /media/ramdisk    tmpfs    defaults,size=16M,mode=1777    0  0

第二個欄位是 mount point。另外在 option 欄位可以透過 size 設定分配的檔案系統大小。2

設定完成後,可以透過 mount -a 立即掛載。

Tags:Linux

YouTube 影片格式筆記

Posted on 2022 年 2 月 18 日2022 年 2 月 18 日 By 日落 在〈YouTube 影片格式筆記〉中尚無留言

前陣子錄影上傳到 YouTube:

高鐵嘉義到彰化區間漂亮的田野風景

發現使用舊有的 yt-dlp 參數會抓不到想要的影片格式,透過 --list-formats 和 --list-subs 工具以後,才知道 YouTube 的影片格式有這麼多種,難怪上傳完成到上架要等很久。

More “YouTube 影片格式筆記” »

Tags:YouTube, 生活雜記

在 Laravel 建立並自動更新 sitemap.xml

Posted on 2022 年 2 月 17 日2022 年 2 月 17 日 By 日落 在〈在 Laravel 建立並自動更新 sitemap.xml〉中有 1 則留言

sitemap.xml 應該算是 SEO 中相當重要的一個檔案,告訴搜尋引擎到底網站中有哪些資源是公開瀏覽的,可惜 Laravel framework 並沒有支援這項功能,必須透過其他工具達成。

以下介紹二個目前看到比較欣賞的解決方法。

More “在 Laravel 建立並自動更新 sitemap.xml” »

Tags:Laravel, PHP, 網路架站

Cyberpubk 2077 更新

Posted on 2022 年 2 月 16 日2022 年 2 月 16 日 By 日落 在〈Cyberpubk 2077 更新〉中有 1 則留言

想玩遊戲時被自動更新打斷,看了一下還有什麼功能可以更新,發現還不少:

  • 可以買處住,好像還可以自己裝潢的樣子
  • 地圖檢視工具更新,可以過濾掉不需要的資訊標示
  • 新增武器、零件和有的沒的
  • 更新 AI 系統
  • 調整交通工具駕駛時的操作界面

官方給的更新資訊細節太多,懶得看完,有興趣的自己去追:https://store.steampowered.com/news/app/1091500/view/5121158897695279077

Tags:遊戲

文章分頁

上一頁 1 ... 41 42 43 ... 318 下一頁

其他

關於我  (About me)

  文章 RSS Feed

  留言 RSS Feed

Apache AWS Bash C/C++ Docker FreeBSD GCP Git Google Java JavaScript Laravel Linux Microsoft MSSQL MySQL Nginx PHP PHPUnit PostgreSQL Python Qt Ubuntu Unix Vim Web Windows WordPress XD 作業系統 分享 好站推薦 專題 攝影 新奇搞笑 新聞 旅遊 生活雜記 程式設計 網路架站 網頁設計 資訊學習 資訊安全 遊戲 音樂


創用 CC 授權條款
本著作係採用創用 CC 姓名標示-相同方式分享 4.0 國際 授權條款授權.