33 for (
auto* i =
addrs; i !=
nullptr; i = i->ifa_next)
35 if (i->ifa_addr->sa_family ==
AF_LINK)
56 for (
auto* i =
addrs; i !=
nullptr; i = i->ifa_next)
98 hasBodyDataToSend (addParametersToRequestBody || url.hasBodyDataToSend()),
99 httpRequestCmd (hasBodyDataToSend ?
"POST" :
"GET")
110 void withExtraHeaders (
const String& extraHeaders)
115 headers << extraHeaders;
124 int getStatusCode()
const {
return statusCode; }
125 StringPairArray getRequestHeaders()
const {
return WebInputStream::parseHttpHeaders (headers); }
133 for (
int i = 0; i < headerLines.
size(); ++i)
136 auto key =
headersEntry.upToFirstOccurrenceOf (
": ",
false,
false);
137 auto value =
headersEntry.fromFirstOccurrenceOf (
": ",
false,
false);
143 return responseHeaders;
151 if (hasBeenCancelled)
155 address = url.
toString (! addParametersToRequestBody);
156 statusCode = createConnection (listener, numRedirectsToFollow);
158 return statusCode != 0;
165 hasBeenCancelled =
true;
173 bool isError()
const {
return socketHandle < 0; }
174 bool isExhausted() {
return finished; }
175 int64 getPosition() {
return position; }
176 int64 getTotalLength() {
return contentLength; }
180 if (finished || isError())
183 if (isChunked && ! readingChunk)
185 if (position >= chunkEnd)
193 if (read (&c, 1) != 1 || c !=
'\r'
194 || read (&c, 1) != 1 || c !=
'\n')
203 if (read (&c, 1) != 1)
226 chunkEnd += chunkSize;
230 bytesToRead =
static_cast<int> (chunkEnd - position);
235 if (
poll (&
pfd, 1, timeOutMs) <= 0)
244 position += bytesRead;
278 int socketHandle = -1, levelsOfRedirection = 0;
282 int64 contentLength = -1, position = 0;
283 bool finished =
false;
284 const bool addParametersToRequestBody, hasBodyDataToSend;
286 int numRedirectsToFollow = 5;
289 bool isChunked =
false, readingChunk =
false;
291 bool hasBeenCancelled =
false;
297 if (socketHandle >= 0)
300 ::close (socketHandle);
306 levelsOfRedirection = 0;
313 if (hasBodyDataToSend)
314 WebInputStream::createHeadersAndPostData (url,
317 addParametersToRequestBody);
341 if (
proxyURL.startsWithIgnoreCase (
"http://"))
360 hints.ai_flags = AI_NUMERICSERV;
370 socketHandle = hasBeenCancelled ? -1
371 :
socket (result->ai_family, result->ai_socktype, 0);
374 if (socketHandle == -1)
380 int receiveBufferSize = 16384;
388 if (::connect (socketHandle, result->ai_addr, result->ai_addrlen) == -1)
399 headers, postData, httpRequestCmd));
415 auto status =
responseHeader.fromFirstOccurrenceOf (
" ",
false,
false)
416 .substring (0, 3).getIntValue();
418 auto location = findHeaderItem (headerLines,
"Location:");
421 && status >= 300 && status < 400
422 && location.isNotEmpty() && location != address)
424 if (! (location.startsWithIgnoreCase (
"http://")
425 || location.startsWithIgnoreCase (
"https://")
426 || location.startsWithIgnoreCase (
"ftp://")))
429 if (location.startsWithChar (
'/'))
432 location = address +
"/" + location;
444 isChunked = (findHeaderItem (headerLines,
"Transfer-Encoding:") ==
"chunked");
462 && ! (finished || isError()))
466 if (read (&c, 1) != 1)
479 if (header.startsWithIgnoreCase (
"HTTP/"))
488 dest <<
"\r\n" << key <<
' ' << value;
494 dest << httpRequestCmd <<
' ' << path <<
" HTTP/1.1\r\nHost: " << host;
505 const String& httpRequestCmd)
517 writeValueIfNotPresent (header,
userHeaders,
"Connection:",
"close");
528 header <<
"\r\n\r\n";
562 if (! url.startsWithIgnoreCase (
"http://"))
565 auto nextSlash = url.indexOfChar (7,
'/');
566 auto nextColon = url.indexOfChar (7,
':');
578 port = url.substring (
nextColon + 1).getIntValue();
587 host = url.substring (7);
600 for (
int i = 0; i < lines.
size(); ++i)
601 if (lines[i].startsWithIgnoreCase (
itemName))
612 return URL::DownloadTask::createFallbackDownloader (*
this, targetLocation, options);
Holds a resizable array of primitive or copy-by-value objects.
bool addIfNotAlreadyThere(ParameterType newElement)
Appends a new element at the end of the array as long as the array doesn't already contain it.
Represents a local file or directory.
Automatically locks and unlocks a mutex object.
Very simple container class to hold a pointer to some data on the heap.
Represents a MAC network card adapter address ID.
static void findAllAddresses(Array< MACAddress > &results)
Populates a list of the MAC addresses of all the available network cards.
A class to hold a resizable block of raw data.
size_t getSize() const noexcept
Returns the block's current allocated size, in bytes.
Writes data to an internal memory buffer, which grows as required.
String toString() const
Attempts to detect the encoding of the data and convert it to a string.
size_t getDataSize() const noexcept
Returns the number of bytes of data that have been written to the stream.
MemoryBlock getMemoryBlock() const
Returns a copy of the stream's data as a memory block.
virtual bool writeByte(char byte)
Writes a single byte to the stream.
static bool JUCE_CALLTYPE openEmailWithAttachments(const String &targetEmailAddress, const String &emailSubject, const String &bodyText, const StringArray &filesToAttach)
Tries to launch the OS's default email application to let the user create a message.
Helper class providing an RAII-based mechanism for temporarily setting and then re-setting a value.
A special array for holding a list of strings.
static StringArray fromLines(StringRef stringToBreakUp)
Returns an array containing the lines in a given string.
int size() const noexcept
Returns the number of strings in the array.
void trim()
Deletes any whitespace characters from the starts and ends of all the strings.
A container for holding a set of strings which are keyed by another string.
void set(const String &key, const String &value)
Adds or amends a key/value pair.
bool endsWithChar(juce_wchar character) const noexcept
Tests whether the string ends with a particular character.
bool containsIgnoreCase(StringRef text) const noexcept
Tests whether the string contains another substring.
String trimEnd() const
Returns a copy of this string with any whitespace characters removed from the end.
static String fromUTF8(const char *utf8buffer, int bufferSizeBytes=-1)
Creates a String from a UTF-8 encoded buffer.
bool isNotEmpty() const noexcept
Returns true if the string contains at least one character.
static uint32 getMillisecondCounter() noexcept
Returns the number of millisecs since a fixed event (usually system startup).
Holds options that can be specified when starting a new download with downloadToFile().
Represents a URL and has a bunch of useful functions to manipulate it.
String toString(bool includeGetParameters) const
Returns a string version of the URL.
URL withNewSubPath(const String &newPath) const
Returns a new version of this URL with a different sub-path.
std::unique_ptr< DownloadTask > downloadToFile(const File &targetLocation, String extraHeaders=String(), DownloadTaskListener *listener=nullptr, bool usePostCommand=false)
This function is replaced by a new overload accepting a DownloadTaskOptions argument.
#define JUCE_MAJOR_VERSION
Current JUCE version number.
void zerostruct(Type &structure) noexcept
Overwrites a structure or object with zeros.
constexpr Type jmin(Type a, Type b)
Returns the smaller of two values.
constexpr Type jmax(Type a, Type b)
Returns the larger of two values.
Type unalignedPointerCast(void *ptr) noexcept
Casts a pointer to another type via void*, which suppresses the cast-align warning which sometimes ar...
unsigned int uint32
A platform-independent 32-bit unsigned integer type.
unsigned char uint8
A platform-independent 8-bit unsigned integer type.
long long int64
A platform-independent 64-bit integer type.