OpenShot Audio Library | OpenShotAudio 0.3.2
Loading...
Searching...
No Matches
juce_WebInputStream.cpp
1/*
2 ==============================================================================
3
4 This file is part of the JUCE library.
5 Copyright (c) 2017 - ROLI Ltd.
6
7 JUCE is an open source library subject to commercial or open-source
8 licensing.
9
10 The code included in this file is provided under the terms of the ISC license
11 http://www.isc.org/downloads/software-support-policy/isc-license. Permission
12 To use, copy, modify, and/or distribute this software for any purpose with or
13 without fee is hereby granted provided that the above copyright notice and
14 this permission notice appear in all copies.
15
16 JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
17 EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
18 DISCLAIMED.
19
20 ==============================================================================
21*/
22
23namespace juce
24{
25
27 : pimpl (new Pimpl (*this, url, usePost)), hasCalledConnect (false)
28{
29}
30
31WebInputStream::~WebInputStream()
32{
33 delete pimpl;
34}
35
36WebInputStream& WebInputStream::withExtraHeaders (const String& extra) { pimpl->withExtraHeaders (extra); return *this; }
37WebInputStream& WebInputStream::withCustomRequestCommand (const String& cmd) { pimpl->withCustomRequestCommand(cmd); return *this; }
38WebInputStream& WebInputStream::withConnectionTimeout (int t) { pimpl->withConnectionTimeout (t); return *this; }
39WebInputStream& WebInputStream::withNumRedirectsToFollow (int num) { pimpl->withNumRedirectsToFollow (num); return *this; }
40StringPairArray WebInputStream::getRequestHeaders() const { return pimpl->getRequestHeaders(); }
41StringPairArray WebInputStream::getResponseHeaders() { connect (nullptr); return pimpl->getResponseHeaders(); }
42bool WebInputStream::isError() const { return pimpl->isError(); }
43void WebInputStream::cancel() { pimpl->cancel(); }
44bool WebInputStream::isExhausted() { return pimpl->isExhausted(); }
45int64 WebInputStream::getPosition() { return pimpl->getPosition(); }
46int64 WebInputStream::getTotalLength() { connect (nullptr); return pimpl->getTotalLength(); }
47int WebInputStream::read (void* buffer, int bytes) { connect (nullptr); return pimpl->read (buffer, bytes); }
48bool WebInputStream::setPosition (int64 pos) { return pimpl->setPosition (pos); }
49int WebInputStream::getStatusCode() { connect (nullptr); return pimpl->getStatusCode(); }
50
52{
53 if (hasCalledConnect)
54 return ! isError();
55
56 hasCalledConnect = true;
57 return pimpl->connect (listener);
58}
59
60StringPairArray WebInputStream::parseHttpHeaders (const String& headerData)
61{
64
65 // ignore the first line as this is the status line
66 for (int i = 1; i < headerLines.size(); ++i)
67 {
69
70 if (headersEntry.isNotEmpty())
71 {
72 const String key (headersEntry.upToFirstOccurrenceOf (": ", false, false));
73 const String value (headersEntry.fromFirstOccurrenceOf (": ", false, false));
74 const String previousValue (headerPairs [key]);
75 headerPairs.set (key, previousValue.isEmpty() ? value : (previousValue + "," + value));
76 }
77 }
78
79 return headerPairs;
80}
81
82void WebInputStream::createHeadersAndPostData (const URL& aURL, String& headers, MemoryBlock& data)
83{
84 aURL.createHeadersAndPostData (headers, data);
85}
86
87} // namespace juce
bool isEmpty() const noexcept
Definition juce_Array.h:222
int size() const noexcept
Definition juce_Array.h:215
void set(int indexToChange, ParameterType newValue)
Definition juce_Array.h:542
static StringArray fromLines(StringRef stringToBreakUp)
WebInputStream & withConnectionTimeout(int timeoutInMs)
WebInputStream & withExtraHeaders(const String &extraHeaders)
bool setPosition(int64 wantedPos) override
WebInputStream & withNumRedirectsToFollow(int numRedirects)
int64 getTotalLength() override
bool connect(Listener *listener)
StringPairArray getRequestHeaders() const
WebInputStream & withCustomRequestCommand(const String &customRequestCommand)
int read(void *destBuffer, int maxBytesToRead) override
WebInputStream(const URL &url, const bool usePost)
StringPairArray getResponseHeaders()