Git Product home page Git Product logo

http's Introduction

PSR-7 HTTP message implementation.

HTTP messages are the foundation of web development. Web browsers and HTTP clients such as cURL create HTTP request messages that are sent to a web server, which provides an HTTP response message. Server-side code receives an HTTP request message, and returns an HTTP response message.

Whatever tool kit a PHP web application is built upon, HTTP messages always behave in the same way. PSR-7 is a set of PHP interfaces defined by the PHP Framework Interop Group in order to produce code that can be shared between application implementations.

This repository is an implementation of the PSR-7 interfaces for use within PHP.Gt/WebEngine, but can be used in any other PHP web application thanks to the interoperability of PSR-7.


PHP.Gt/Http build status PHP.Gt/Http code quality PHP.Gt/Http code coverage PHP.Gt/Http latest release PHP.Gt/Http documentation

http's People

Contributors

dependabot-preview[bot] avatar dependabot-support avatar dependabot[bot] avatar g105b avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar

Forkers

isabella232

http's Issues

Where is my page redirecting from?

When doing $response->redirect("/somewhere/"), it would be nice if the redirect function added an extra header to the response, which was the name of the calling function that initiated the response. When there's a lot of _common scripts that all control things like auth, it can be a bit confusing.

Improve WebAPI compatibility

https://developer.mozilla.org/en-US/docs/Web/API

There are a few classes in the WebAPI that have functionality shared by this implementation of PSR-7 which should be implemented.

Functions:

  • Message::arrayBuffer() - Returns a promise
  • Message::blob() - Returns a promise
  • Message::formData() - Returns a promise
  • Message::json() - Returns a promise
  • Message::text() - Returns a promise

Properties:

  • Response::ok
  • Response::headers
  • Response::redirected
  • Response::status
  • Response::statusText
  • Response::type
  • Response::uri
  • Response::useFinalUri

  • Request::cache
  • Request::context
  • Request::credentials
  • Request::destination
  • Request::headers
  • Request::integrity
  • Request::method
  • Request::mode
  • Request::redirect
  • Request::referrer
  • Request::referrerPolicy
  • Request::url

Case insensitive functions

Headers do not care about case. Getting a value or checking a value shouldn't make any difference if it;s accept or Accept or ACCEPT.

Response redirect/reload functions

To increase testability and general code quality, the process of sending the Location header for a reload or redirect should be exposed as a function on the Response. This is only possible by having a callback stored for execution when the header is sent, which will allow WebEngine to intercept the response logic and exit early.

Header hyphens vs. underscores

When dealing directly with the Request object, hyphenated headers are converted to underscores, which is incorrect.

See:

$request = $this->container->get(Request::class);
$pagination = null;
if($request->hasHeader("x_pagination")) {
	$pagination = $request->getHeaderLine("x_pagination");
}

The actual header name is x-pagination, as per this JavaScript:

fetch(location.href, {
	headers: {
		"x-pagination": page
	}
}).then(response => {
	// ...
});

Uploading files and posting data using FormData

There needs to be some documented feature for how to use FormData for posting data, and how to use some kind of FileUpload class to upload binary content over HTTP. Is there a PHP built in class for this?

RequestFactory - create from globals

To increase PSR-15 compatibility, it would be super-useful to be able to create a Request object from the current global state, not requiring any Gt-specific objects at all.

Response: Synchronous await methods

Following on from PhpGt/Fetch#153, it would be nice to simulate the "await" keyword in JS:

JS version:

const response = await fetch("/api");
const jsonObject = await response.json();

PHP version:

$response = $http->awaitFetch("/api");
$jsonObject = $response->awaitJson();

Rediects - ensure the URI is always absolute, with full host and scheme

An app I'm working on has a <0.1% session fail rate, but has a high traffic rate, so the issue is being brought to my attention every day or so. After researching what is causing the sessions to rotate, there's a strong indication that it only happens when a "relative" redirect is made.

If I'm right, the issue only happens after:

$response->redirect("./something/"); or $response->redirect("../"); for example.

When the Response is constructed, it could be passed the current request uri as an optional parameter - and if this parameter is present, it can use the available parts of the uri to normalise an absolute URI.

Will this solve the issue though?

Immutable headers

Currently all of the classes in Http are immutable (with instead of set functions), but Headers are not. For consistency alone this should be changed, but it would also improve code cleanness throughout.

Confusion because of PSR-7

Apparently it's a good idea to use PSR-7 when writing libraries that implement URLs, Requests, Responses, etc. but I'm coming to the opinion that it really doesn't matter at all, and PSRs actually just get in the way of what you're trying to do.

If this library's intention was to be interoperable with other Http libraries, maybe it would be a good idea to implement PSRs, but who has ever inter-operated anything in PHP? You refactor and get the job done.

This is not a rant about PSR. It's great to have consistency. But this library is suffering, because PSRs are not compatible with web standards.

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.