PluginProbe ʕ •ᴥ•ʔ
WP Mail SMTP by WPForms – The Most Popular SMTP and Email Log Plugin / 3.7.0
WP Mail SMTP by WPForms – The Most Popular SMTP and Email Log Plugin v3.7.0
0.9.6 1.0.0 1.0.1 1.0.2 1.1.0 1.2.0 1.2.1 1.2.2 1.2.3 1.2.4 1.2.5 1.3.0 1.3.1 1.3.2 1.3.3 1.4.0 1.4.1 1.4.2 1.5.0 1.5.1 1.5.2 1.6.0 1.6.2 1.7.0 1.7.1 1.8.0 1.8.1 1.9.0 2.0.0 2.0.1 2.1.1 2.2.1 2.3.1 2.4.0 2.5.0 2.5.1 2.6.0 2.7.0 2.8.0 2.9.0 3.0.1 3.0.2 3.0.3 3.1.0 3.10.0 3.11.0 3.11.1 3.2.0 3.2.1 3.3.0 3.4.0 3.5.0 3.5.1 3.5.2 3.6.1 3.7.0 3.8.0 3.8.2 3.9.0 4.0.1 4.1.0 4.1.1 4.2.0 4.3.0 4.4.0 4.5.0 4.6.0 4.7.0 4.7.1 4.8.0 trunk 0.10.0 0.10.1 0.11.1 0.11.2 0.3.1 0.3.2 0.4 0.4.1 0.4.2 0.5.0 0.5.1 0.5.2 0.6 0.7 0.8 0.8.2 0.8.3 0.8.4 0.8.5 0.8.6 0.8.7 0.9.0 0.9.1 0.9.2 0.9.3 0.9.4 0.9.5
wp-mail-smtp / vendor_prefixed / guzzlehttp / guzzle / src / PrepareBodyMiddleware.php
wp-mail-smtp / vendor_prefixed / guzzlehttp / guzzle / src Last commit date
Cookie 3 years ago Exception 3 years ago Handler 3 years ago Client.php 3 years ago ClientInterface.php 3 years ago HandlerStack.php 3 years ago MessageFormatter.php 3 years ago Middleware.php 3 years ago Pool.php 3 years ago PrepareBodyMiddleware.php 3 years ago RedirectMiddleware.php 3 years ago RequestOptions.php 3 years ago RetryMiddleware.php 3 years ago TransferStats.php 3 years ago UriTemplate.php 3 years ago Utils.php 3 years ago functions.php 3 years ago functions_include.php 3 years ago
PrepareBodyMiddleware.php
92 lines
1 <?php
2
3 namespace WPMailSMTP\Vendor\GuzzleHttp;
4
5 use WPMailSMTP\Vendor\GuzzleHttp\Promise\PromiseInterface;
6 use WPMailSMTP\Vendor\GuzzleHttp\Psr7;
7 use WPMailSMTP\Vendor\Psr\Http\Message\RequestInterface;
8 /**
9 * Prepares requests that contain a body, adding the Content-Length,
10 * Content-Type, and Expect headers.
11 */
12 class PrepareBodyMiddleware
13 {
14 /** @var callable */
15 private $nextHandler;
16 /**
17 * @param callable $nextHandler Next handler to invoke.
18 */
19 public function __construct(callable $nextHandler)
20 {
21 $this->nextHandler = $nextHandler;
22 }
23 /**
24 * @param RequestInterface $request
25 * @param array $options
26 *
27 * @return PromiseInterface
28 */
29 public function __invoke(\WPMailSMTP\Vendor\Psr\Http\Message\RequestInterface $request, array $options)
30 {
31 $fn = $this->nextHandler;
32 // Don't do anything if the request has no body.
33 if ($request->getBody()->getSize() === 0) {
34 return $fn($request, $options);
35 }
36 $modify = [];
37 // Add a default content-type if possible.
38 if (!$request->hasHeader('Content-Type')) {
39 if ($uri = $request->getBody()->getMetadata('uri')) {
40 if ($type = \WPMailSMTP\Vendor\GuzzleHttp\Psr7\mimetype_from_filename($uri)) {
41 $modify['set_headers']['Content-Type'] = $type;
42 }
43 }
44 }
45 // Add a default content-length or transfer-encoding header.
46 if (!$request->hasHeader('Content-Length') && !$request->hasHeader('Transfer-Encoding')) {
47 $size = $request->getBody()->getSize();
48 if ($size !== null) {
49 $modify['set_headers']['Content-Length'] = $size;
50 } else {
51 $modify['set_headers']['Transfer-Encoding'] = 'chunked';
52 }
53 }
54 // Add the expect header if needed.
55 $this->addExpectHeader($request, $options, $modify);
56 return $fn(\WPMailSMTP\Vendor\GuzzleHttp\Psr7\modify_request($request, $modify), $options);
57 }
58 /**
59 * Add expect header
60 *
61 * @return void
62 */
63 private function addExpectHeader(\WPMailSMTP\Vendor\Psr\Http\Message\RequestInterface $request, array $options, array &$modify)
64 {
65 // Determine if the Expect header should be used
66 if ($request->hasHeader('Expect')) {
67 return;
68 }
69 $expect = isset($options['expect']) ? $options['expect'] : null;
70 // Return if disabled or if you're not using HTTP/1.1 or HTTP/2.0
71 if ($expect === \false || $request->getProtocolVersion() < 1.1) {
72 return;
73 }
74 // The expect header is unconditionally enabled
75 if ($expect === \true) {
76 $modify['set_headers']['Expect'] = '100-Continue';
77 return;
78 }
79 // By default, send the expect header when the payload is > 1mb
80 if ($expect === null) {
81 $expect = 1048576;
82 }
83 // Always add if the body cannot be rewound, the size cannot be
84 // determined, or the size is greater than the cutoff threshold
85 $body = $request->getBody();
86 $size = $body->getSize();
87 if ($size === null || $size >= (int) $expect || !$body->isSeekable()) {
88 $modify['set_headers']['Expect'] = '100-Continue';
89 }
90 }
91 }
92