Git Product home page Git Product logo

http's Introduction

FastD HTTP Server and Client

Build Status Support Swoole Support PSR7 Latest Stable Version Total Downloads Latest Unstable Version License

简单的 Http 协议组件, 用于解析 Http 请求信息, 实现 PSR-7 标准, 支持 Swoole 扩展.

以上库可以满足大部分 HTTP 请求处理相关工作, 支持 Swoole 处理, 具体请看项目Swoole

要求

  • php >= 5.6

安装

composer require "fastd/http" -vvv

文档

文档

使用

HTTP 组件封装了常用的服务端解释,客户端请求,并且友好集成 Swoole Http Server 解析,实现PSR-7。

HTTP 组件没有对 Session 进行封装, 如果想在项目中支持 Session, 可以通过 Session 组件进行扩展.

获取 pathinfo
use FastD\Http\ServerRequest;

$request = ServerRequest::createServerRequestFromGlobals();

$request->getUri()->getPath();
Swoole Http 服务器
$http = new swoole_http_server("127.0.0.1", 9501);

$http->on('request', function ($request, $response) {
    $server = SwooleServerRequest::createServerRequestFromSwoole($request);
    $response->end($server->getUri()->getPath());
});

$http->start();
cURL 请求

Request 对象内部封装了 cURL 请求, 可以直接通过方法调用

$request = new Request('GET', 'https://api.github.com/');

$request->setReferrer('http://example.com/');

$response = $request->send(); // FastD\Http\Response

响应内容会通过 Response 对象返回。

贡献

非常欢迎感兴趣,愿意参与其中,共同打造更好PHP生态,Swoole生态的开发者。

如果你乐于此,却又不知如何开始,可以试试下面这些事情:

联系

如果你在使用中遇到问题,请联系: [email protected]. 微博: 编码侠

License MIT

http's People

Contributors

janhuang avatar longxinh avatar runnerlee avatar xsharp avatar yyz26371945 avatar zqhong avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

http's Issues

withExpires 方法修改建议

https://github.com/JanHuang/http/blob/a1a3f0a6629f8972308bb27b2b00f44fdfe727cc/src/Response.php#L428

这里加上 Cache-Control: max-age=<seconds> 会好一些。原因:

  • Expires 的话,可能存在客户端和服务端时间不一致,导致缓存失效的情况。
  • 如果 Cache-Control header 存在 "max-age" 或 "s-max-age" 指令时,Expires 头部会被忽略。
  • 最后,Cache-Control 出来的目的,就是取代 Expires 的。Expires 是从 HTTP 1.0 开始定义的,使用它更多是在兼容性方面考虑。

SwooleServerRequest构造ServerRequest出错

更新了最新版http组件后,发现swoole模式下报错,发现是ServerRequest的构造函数第3个参数接收一个array类型,但是现在传递的request为一个object,因此报错
image
之前这个没问题是因为header就是一个array,但是现在改了之后变成了一个object

ServerRequest::createUriFromGlobal() 拼接 URI 时建议优先取 HTTP_HOST,而非 SERVER_NAME

如题。
优先取 SERVER_NAME 可能有什么问题?
比如 nginx 中设置站点为:
server_name ~^(?<subdomain>.+).yourname.com$;
那么拼接的 URI 可能是这样的:
http://~^(?<subdomain>.+).yourname.com$/abc,这样的 URI 不能被正确路由。

更多关于 SERVER_NAMEHTTP_HOST 区别:
https://stackoverflow.com/questions/2297403/what-is-the-difference-between-http-host-and-server-name-in-php

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.