1
0
mirror of https://github.com/esp8266/Arduino.git synced 2025-04-19 23:22:16 +03:00

114 Commits

Author SHA1 Message Date
Paulo Cabral Sanz
32939c4334
Fix reuse for different URIs in HTTPClient::begin (#8466) 2022-03-30 10:35:46 +02:00
david gauchard
e3c79de7c9
httpClient: prevent empty user-agent in header (#8411) 2022-01-03 12:09:31 +01:00
Earle F. Philhower, III
7d971fa45b
Remove warnings, errors during host tests in CI (#8358)
* Remove warnings, errors during host tests in CI

Debug strings often included format parameters which did not exactly match
the passed in format parameters, resulting in warnings in the host test build
process like
````
/home/runner/work/Arduino/Arduino/libraries/ESP8266WiFi/src/ESP8266WiFiAP.cpp:107:20: warning: format ‘%u’ expects argument of type ‘unsigned int’, but argument 3 has type ‘size_t’ {aka ‘long unsigned int’} [-Wformat=]
  107 |         DEBUG_WIFI("[AP] SSID length %u, too long or missing!\n", ssid_len);
      |                                                                   ~~~~~~~~
      |                                                                   |
      |                                                                   size_t {aka long unsigned int}
````

Fix by applying casting or PRxxx macros as appropriate.

Also, fix one debug message which was trying to use a `String` as a `char *`:
````
/home/runner/work/Arduino/Arduino/libraries/ESP8266WiFi/src/ESP8266WiFiMulti.cpp: In member function ‘wl_status_t ESP8266WiFiMulti::connectWiFiMulti(uint32_t)’:
/home/runner/work/Arduino/Arduino/libraries/ESP8266WiFi/src/ESP8266WiFiMulti.cpp:331:34: warning: format ‘%s’ expects argument of type ‘char*’, but argument 3 has type ‘String’ [-Wformat=]
  331 |                 DEBUG_WIFI_MULTI("[WIFIM] Connecting %s\n", ssid);
````

* Clean up SpeedTest.ino host build
2021-11-02 22:41:03 +01:00
Dirk O. Kaar
c312a2eaf1
Implement esp_yield() as a replacement for delay(0)
esp_yield() now also calls esp_schedule(), original esp_yield() function renamed to esp_suspend().

Don't use delay(0) in the Core internals, libraries and examples. Use yield() when the code is
supposed to be called from CONT, use esp_yield() when the code can be called from either CONT or SYS.
Clean-up esp_yield() and esp_schedule() declarations across the code and use coredecls.h instead.

Implement helper functions for libraries that were previously using esp_yield(), esp_schedule() and
esp_delay() directly to wait for certain SYS context tasks to complete. Correctly use esp_delay()
for timeouts, make sure scheduled functions have a chance to run (e.g. LwIP_Ethernet uses recurrent)

Related issues:
- #6107 - discussion about the esp_yield() and esp_delay() usage in ClientContext
- #6212 - discussion about replacing delay() with a blocking loop
- #6680 - pull request introducing LwIP-based Ethernet
- #7146 - discussion that originated UART code changes
- #7969 - proposal to remove delay(0) from the example code
- #8291 - discussion related to the run_scheduled_recurrent_functions() usage in LwIP Ethernet
- #8317 - yieldUntil() implementation, similar to the esp_delay() overload with a timeout and a 0 interval
2021-10-17 00:19:01 +03:00
Max Prokhorov
40b26b769c
Movable HTTPClient and fixing WiFiClient copy (#8237)
- =default for default ctor, destructor, move ctor and the assignment move
- use `std::unique_ptr<WiFiClient>` instead of raw pointer to the client
- implement `virtual std::unique_ptr<WiFiClient> WiFiClient::clone()` to safely copy the WiFiClientSecure instance, without accidentally slicing it (i.e. using the pointer with incorrect type, calling base WiFiClient virtual methods)
- replace headers pointer array with `std::unique_ptr<T[]>` to simplify the move operations
- substitute userAgent with the default one when it is empty
(may be a subject to change though, b/c now there is a global static `String`)

Allow HTTPClient to be placed inside of movable classes (e.g. std::optional, requested in the linked issue) or to be returned from functions. Class logic stays as-is, only the underlying member types are changed.

Notice that WiFiClient connection object is now copied, and the internal ClientContext will be preserved even after the original WiFiClient object was destroyed.

replaces #8236
resolves #8231
and, possibly #5734
2021-10-13 04:19:51 +03:00
Claus Näveke
140d0ffde1
Add writeToPrint to ESP8266HTTPClient (#8056) 2021-09-04 10:46:47 -07:00
Paulo Cabral Sanz
058ce7c08e
Allow control over HTTPClient authorization String allocation (#8225) 2021-09-04 10:17:00 -07:00
behrooz bozorg chami
65db3aec72
Add HTTP delete method (#8214) 2021-09-01 09:42:19 -07:00
Paulo Cabral Sanz
c9f27410f7
Fix NO_GLOBAL_INSTANCES for Serial ports (#8184) 2021-07-17 16:21:37 -07:00
idolpx
1a5ef71298
Change protocol detection so uppercase or lowercase works (#8137)
Make protocol detection case insensitive
2021-06-17 15:48:30 -07:00
Earle F. Philhower, III
60fe7b4ca8
Add code-spell spelling checks to CI (#8067)
Help find and fix silly spelling errors as they are added to the repo.
2021-05-23 08:53:04 -07:00
david gauchard
c720c0d9e8
Stream::send() (#6979) 2021-03-14 17:36:20 -07:00
Paulo Cabral Sanz
98a19ab245
Protect against server hijacking error handling (#7811)
If a server returns "HTTP/1.x -8 OK", for example, it can misguide an application developer into freeing less-important memory so the request can be retried and succeed, when the problem is in the server.

_returnCode is never used anywhere else, but it could still contain a negative value returned by a broken server and therefore could cause troubles in the future (if _returnCode is in fact used)
2021-01-07 21:22:36 -08:00
drderiv
47a57e1ec6
Update to ESP8266HTTPClient.cpp for no Content-Length (#7691)
Response bodies are ignored when _transferEncoding == HTTPC_TE_IDENTITY and there is no Content-Length header.  The added code here fixes that issue.

Add logic to writeToStreamDataBlock to only read what's available so as to avoid timeout, and adjust formatting.
2020-11-20 15:23:43 -08:00
david gauchard
f542175009
httpclient: remove deprecated API (#7617) 2020-09-30 09:59:46 -07:00
david gauchard
11f7d1766e remove (std::nothrow) where nullptr case is not handled
remove legacy new management
2020-08-24 09:51:58 +02:00
david gauchard
6925982284 replace new by new (std::nothrow), remove arduino_new 2020-08-17 18:15:45 +02:00
Earle F. Philhower, III
70e4457041
Remove axTLS from code and documentation (#7437) 2020-07-09 09:21:38 -07:00
david gauchard
52f4cc8de0
httpclient: fix error meaning (#7401)
* httpclient: fix error meaning

* deprecate HTTPC_ERROR_CONNECTION_REFUSED
2020-06-25 09:00:24 +02:00
Jeroen88
157ce57996
bugfix2/ESP8266HTTPClient (#6476)
* Because of git problems, start from a new fork and create a new PR. This was PR #6457

* Style update to pass Travis

* Update ReuseConnectionV2.ino

* fix + enforce testing http code

per @earlephilhower review

* Close connection before ::connecting on HTTP/1.0

HTTPClient never actually closes the TCP connection on its own. It will leave the TCP connection open unless you explicitly do a getString which makes a StreamString and stuffs it with the HTTP server response, at which point the HTTP server itself will close the connection.

If you check the HTTP error code and find failure, unless you do a getString and throw it away, it won't disconnect.  Even in HTTP/1.0 or in cases when you haven't enabled _reuse.

Change the logic in ::connect to only reuse the connection when it is specifically allowed.  Otherwise, fall back to re-connection.

* Adjust example per request

Do single URL get in each loop, avoid infinite for loop at end.

* Fix astyle

* Clean up final pass notice

* Fix example syntax error

Editing code in a web textbox without running it is a painful process.


Co-authored-by: Earle F. Philhower, III <earlephilhower@yahoo.com>
2020-05-15 17:12:49 -04:00
Patryk (PsychoX) Ludwikowski
d91f1dac36
Better follow redirection for HTTPClient (#7157)
* Add way to force follow redirections in `HTTPClient`

* Follow other client implementations about `HTTP_CODE_FOUND`; Small rewrite of `sendRequest` function of `HTTPClient`

* Better names for follow redirection modes in `HTTPClient`

Also changed a bit order of the enums (0 element to be DISABLED)

* Rewrite `sendRequest` to remove recursion

Also got rid of unnecessary `redirectCount` field. Now redirect counting and limiting is handled in `sendRequest` directly.

* Use new `setFollowRedirects` of `HTTPClient` instead deprecated one.

* More explanatory comment for `followRedirects_t` in HTTPClient
2020-03-25 23:33:54 +01:00
ramirocarra
378c1f14c7
Update ESP8266HTTPClient.cpp (#7051)
sendRequest has a major problem when sending a big payload, the comparator in the IF loop has its two operators changed, so the last part of payload is never sent
2020-02-01 20:11:00 -03:00
liebman
9e9515b49f clear _canReuse in setUrl if its not a local redirect (#7039) 2020-01-28 00:35:16 -03:00
Dirk Mueller
de307623b2 Move a couple larger strings from rodata to flash (#6976) 2020-01-02 22:26:08 -03:00
Dirk Mueller
5d5200af41 Reduce temporary string creation in HTTPClient::sendHeader (#6937)
* Reduce temporary string creation/reallocation in HTTPClient

This improves both performance due to fewer memory allocations/copies
as well as reduces code size by ~ 25% (150 bytes)

* Add more correct reservation calculation

Co-authored-by: Develo <deveyes@gmail.com>
2019-12-28 19:48:47 -08:00
Dirk Mueller
698ffc3498 Various String handling cleanups (#6945)
Use the proper api (::clear(), isEmpty()) instead of doing
comparisons/assignments of empty strings. Also fix mixture
of tabs and spaces in the source code.
2019-12-26 17:03:18 -03:00
Develo
32792483cc Fix pointer arithmetic (#6830)
Actually advance position while looping
2019-11-24 11:42:17 +01:00
Earle F. Philhower, III
8f6e0dd339 Allow for POSTs larger than a few 100 bytes (#6800)
This is all @dirkx , whose PR unfortunately got borked when we were
trying to update it to the new format.  As @dirkx said:

When sending POST responses of well over a K - _write() may not sent it
all. Make sure we do -- but cap the individual writes - as somehow large
2-3k blobs seem to cause instability (on my 12F units).

Supercedes #2528
2019-11-24 01:53:29 -03:00
liebman
bbfe2c2035 remove clear() before beginInternal() so _location is not cleared before its passed to beginInternal() (#6786) 2019-11-18 16:41:24 -03:00
Dirk Mueller
14262af0d1 Cleanup base64::encode functions (#6607)
* Cleanup base64::encode functions

The implementation choice here using libb64 is generally good as it
is a relatively fast implementation, however the adaptation to
use PROGMEM for the translation function was a bad choice, as reading
randomly PROGMEM with byte-wide access is very very very slow.

Doing a naive if-snake is between 20% and 55% faster and uses less
flash (about 120 bytes less) and also for reasons I don't understand
8 bytes less data RAM (maybe the removal of static?).

In addition the base64::encode function was allocating for larger
input a huge amount of memory (twice the total size). we can reduce
that by doing a chunk-wise conversation to base64.

* Create authorisation base64 encoded string without newlines

Rather than first creating a string with newlines and then
stripping it away in the fast path of constructing the query,
we can call the right method and trust that the result does
not have newlines anymore.
2019-10-31 13:18:36 -07:00
Dirk Mueller
8bc5a10d6d Further const correctness / String by reference passing cleanups (#6571)
There are actually several instances where we pass in read-only
parameters as pass-by-value, where in the case of String() that
is inefficient as it involves copy-constructor/temp string creations.

We can avoid that, similarly to single character string concatenations
done via string literals instead of char literals.
2019-10-31 16:02:39 +01:00
Dirk Mueller
3890e1af1e Put longer string literals into PROGMEM (#6588)
* Put longer string literals into PROGMEM

* Use Flash Strings for Debug output

This is hopefully very infrequently used, so it shouldn't
be in main memory.
2019-10-03 23:17:36 -03:00
Dirk Mueller
2a83adb0fd Fix setURL() handling of path-only parameters (#6570)
The function accidentally compared the current location instead
of the passed in (new) location, which didn't match intended
logic and the code comment.
2019-09-30 20:23:25 -07:00
david gauchard
2d1acfa9a4
add or improve some debug messages (#6508) 2019-09-12 16:08:52 +02:00
Jeroen88
60d519e235 Bugfix/esp8266 http client (#6176) 2019-08-26 16:12:50 +02:00
teo1978
a8873c2364 fix documented parameter (#6392) 2019-08-07 14:16:07 +02:00
mayankgour13
8b1af68e3f Infinite loop while passing File(FS.h) resolved (#5038)
Stream.available() never reaches to -1 which makes it an infinite loop. When File (FS.h) goes empty it reaches to 0 not -1.
2019-07-05 09:02:01 -04:00
aesapronov
e81bb6f57c HTTPClient: Added possibility of sending POST with empty payload (#4275)
* Added possibility of sending POST with empty payload
Specification does not prohibit the sending of an empty POST requests. In this case "Content-Length: 0" should be set. See thread here: http://lists.w3.org/Archives/Public/ietf-http-wg/2010JulSep/0276.html
2019-07-04 13:00:54 +02:00
Allman-astyler
eea9999dc5 Revert "Allman now (#6080)" (#6090)
This reverts commit 98125f88605cd7e46e9be4e1b3ad0600dd5d2b51.
2019-05-14 00:09:54 +02:00
Allman-astyler
98125f8860 Allman now (#6080)
* switch restyle script for CI

* remove confirmation

* restyle with allman
2019-05-13 16:41:34 +02:00
david gauchard
e67cc90b7a
Honor timeout in HTTPClient (#6056)
* check for timeout in ESP8266HTTPClient::writeToStreamDataBlock
2019-05-06 21:26:17 +02:00
david gauchard
e5b4de3633
fix DEBUG macros (#5728)
* fix DEBUG macros

All fmt strings in flash
fix #5658

This also allows to avoid warnings and easy mistakes with (no brace):
    if (something)
        DEBUGV("blah");

* use newlib unaligned-compatible printf for DEBUGV

* remove useless putprintf since ::printf already uses ets_putc
2019-03-14 11:19:21 +01:00
liebman
e46ccae9d5 optionally allow redirects on HTTPClient & OTA updates (#5009)
* optionally allow redirects on http OTA updates

* Refactored HTTPClient::begin(url...) & setURL functions, now only beginInternal parses URL, sets ports
Added HTTPRedirect example.

* fix indentation for style check

* add space after while for style check

* don't use deprecated begin method in redirect example

* moved redirect handling code to HTTPClient.
only GET and HEAD requests are currently handled automatically
Redirects that fail to be automatically handled return the redirect code as before

* added support for POST/303 redirect
added device redirect tests

* add missing getLocation() implementation

* if the new location is only a path then only update the URI
2019-03-13 01:51:17 +01:00
david gauchard
92373a9837 Deprecate axTLS, update examples (#5366)
* update examples

* fix serial<->tcp example, use STASSID instead of SSID (name collision)

* fix HTTPSRequest.ino

* update AxTLS HTTPS examples, update AxTLS API to deprecated

* fixes

* fixes + fix astyle (no preproc directives) + restyling script

* fix HTTPClient library

* fixes

* common.sh: do not reload arduino when already present (for locally CI testing)

* common.sh: do not reload ArduinoJson when already present (for locally CI testing)

* fix

* fix

* fix deprecated example

* fix WiFiHTTPSServer.ino

* reduce footprint

* wipfix

* fix led builtin

* fix example

* finished updating APSSID on all examples

* style

* restyle examples

* helper to run CI test locally

* local CI runner more verbose

* +const

* deprecation deprecation

* deprecation

* Update NTPClient.ino

const char[] => const char *

* Update interactive.ino

const char[] => const char *
2018-11-29 20:49:27 -08:00
david gauchard
116da1881c update HTTPCLIENT_1_1_COMPATIBLE (#5389)
* update HTTPCLIENT_1_1_COMPATIBLE: #if instead if #ifdef, set to 1 by default
host emulation updates

* host CI: minor simplification

* revert -j
2018-11-29 10:42:44 -08:00
Earle F. Philhower, III
fcdffc5dfd
Save 2.3K in HTTPClient debug mode by PSTR (#5387)
Convert the HTTPClient debug macro to store strings in PROGMEM and
use the printf_P method to dump them.

Saves ~2.3KB heap when in debug mode.
2018-11-29 06:37:07 -08:00
david gauchard
74ca42f829 Sketch emulation on host (#5342)
* WIP compile examples on host with 'make examples'

* WIP bufferize tcp input

* WIP Makefile

* WIP network to rework, tcp/udp to factorize, udp addresses broken

* minor changes to the core

* WIP basic udp working

* WIP mdns

* WIP mcast receiving, not sending

* WIP mdns OK

* beta version

* SSL + doc

* update travis host test command

* licenses

* typo

* doc: arduino builder is not around: declare functions before calling them

* fix with latest SSL PR, compile in 32 bits mode

* fix make clean

* make -m32 optional

* 32bits compiler ability tester

* WIP

* WIP (fix 1 vtable error, still another one to hunt with using spiffs)

* example astyle

* fix os_printf_plus

* load / save mock spiffs

* fix style

* fix using spiffs/mock

* don't mess ram

* update doc

* remove leftover

* optimization -Os except for CI, rename ARCH32 to FORCE32

* revert useless cast (not even compiled)

* remove unused function

* use proper type for pointer arithmetics

* makefile: sketch object and cpp file moved to bin/ directories
easier to clean, and IDE don't like them

* changes for review

* make use of %zd

* less verbose makefile by default (option)

* update readme
2018-11-20 18:51:45 -02:00
liebman
a42c3c399b Fix device/test_http_client tests (#5309)
* update HTTPClient API usage
skip the second POST as end() has different semantics and nulls the client pointer
use bearssl in ssl tests
add delay in python side when shutting down http web server so MacOS does not complain about address already in use

* fix crash if GET/POST was called after end() without a new begin()
update double POST test to insure no crash if POST called after end()
test now are for both AxTLS and BearSSL

* fix small comment typo
2018-11-06 22:56:10 -03:00
Jeroen88
e954022b94 Bugfix/esp8266 http client (#5250)
* Removed _client->stop() from destructor; some minor changes

* Changed BasicHttpsClient.ino to allocate BearSSL::WiFiClientSecure object on the heap in stead of stack

* Removed unnecessary code

* Correcting bad fix for #5216

* Minor formatting to pass Travis tests

* Changed client * to std::unique_ptr<> client

* Updated example
2018-10-21 10:42:55 -03:00
Jeroen88
c8497da676 ESP8266httpClient crash-on-destructor bugfix (#5220)
* Removed _client->stop() from destructor; some minor changes

* Changed BasicHttpsClient.ino to allocate BearSSL::WiFiClientSecure object on the heap in stead of stack
2018-10-11 15:34:25 -07:00