OpenShot Audio Library | OpenShotAudio: juce_WebInputStream.cpp Source File

OpenShot Audio Library | OpenShotAudio 0.3.0

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
26WebInputStream::WebInputStream (const URL& url, const bool usePost)
27 : pimpl (new Pimpl (*this, url, usePost)), hasCalledConnect (false)
28{
29}
30
31WebInputStream::~WebInputStream()
32{
33 delete pimpl;
34}
35
36 WebInputStream& WebInputStream::withExtraHeaders (const String& extra) { pimpl->withExtraHeaders (extra); return *this; }
37 WebInputStream& WebInputStream::withCustomRequestCommand (const String& cmd) { pimpl->withCustomRequestCommand(cmd); return *this; }
38 WebInputStream& WebInputStream::withConnectionTimeout (int t) { pimpl->withConnectionTimeout (t); return *this; }
39 WebInputStream& WebInputStream::withNumRedirectsToFollow (int num) { pimpl->withNumRedirectsToFollow (num); return *this; }
40 StringPairArray WebInputStream::getRequestHeaders() const { return pimpl->getRequestHeaders(); }
41 StringPairArray WebInputStream::getResponseHeaders() { connect (nullptr); return pimpl->getResponseHeaders(); }
42 bool WebInputStream::isError() const { return pimpl->isError(); }
43 void WebInputStream::cancel() { pimpl->cancel(); }
44 bool WebInputStream::isExhausted() { return pimpl->isExhausted(); }
45int64 WebInputStream::getPosition() { return pimpl->getPosition(); }
46int64 WebInputStream::getTotalLength() { connect (nullptr); return pimpl->getTotalLength(); }
47 int WebInputStream::read (void* buffer, int bytes) { connect (nullptr); return pimpl->read (buffer, bytes); }
48 bool WebInputStream::setPosition (int64 pos) { return pimpl->setPosition (pos); }
49 int WebInputStream::getStatusCode() { connect (nullptr); return pimpl->getStatusCode(); }
50
51 bool WebInputStream::connect (Listener* listener)
52{
53 if (hasCalledConnect)
54 return ! isError();
55
56 hasCalledConnect = true;
57 return pimpl->connect (listener);
58}
59
60 StringPairArray WebInputStream::parseHttpHeaders (const String& headerData)
61{
62 StringPairArray headerPairs;
63 StringArray headerLines = StringArray::fromLines (headerData);
64
65 // ignore the first line as this is the status line
66 for (int i = 1; i < headerLines.size(); ++i)
67 {
68 const String& headersEntry = headerLines[i];
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
juce::StringArray
Definition: juce_StringArray.h:35
juce::StringArray::fromLines
static StringArray fromLines(StringRef stringToBreakUp)
Definition: juce_StringArray.cpp:402
juce::StringArray::size
int size() const noexcept
Definition: juce_StringArray.h:135
juce::StringPairArray
Definition: juce_StringPairArray.h:35
juce::StringPairArray::set
void set(const String &key, const String &value)
Definition: juce_StringPairArray.cpp:105
juce::String
Definition: juce_String.h:39
juce::String::upToFirstOccurrenceOf
String upToFirstOccurrenceOf(StringRef substringToEndWith, bool includeSubStringInResult, bool ignoreCase) const
Definition: juce_String.cpp:1596
juce::String::isNotEmpty
bool isNotEmpty() const noexcept
Definition: juce_String.h:302
juce::String::fromFirstOccurrenceOf
String fromFirstOccurrenceOf(StringRef substringToStartFrom, bool includeSubStringInResult, bool ignoreCase) const
Definition: juce_String.cpp:1576
juce::URL
Definition: juce_URL.h:38
juce::WebInputStream::Listener
Definition: juce_WebInputStream.h:37
juce::WebInputStream
Definition: juce_WebInputStream.h:33
juce::WebInputStream::withConnectionTimeout
WebInputStream & withConnectionTimeout(int timeoutInMs)
Definition: juce_WebInputStream.cpp:38
juce::WebInputStream::withExtraHeaders
WebInputStream & withExtraHeaders(const String &extraHeaders)
Definition: juce_WebInputStream.cpp:36
juce::WebInputStream::setPosition
bool setPosition(int64 wantedPos) override
Definition: juce_WebInputStream.cpp:48
juce::WebInputStream::withNumRedirectsToFollow
WebInputStream & withNumRedirectsToFollow(int numRedirects)
Definition: juce_WebInputStream.cpp:39
juce::WebInputStream::getStatusCode
int getStatusCode()
Definition: juce_WebInputStream.cpp:49
juce::WebInputStream::isExhausted
bool isExhausted() override
Definition: juce_WebInputStream.cpp:44
juce::WebInputStream::getTotalLength
int64 getTotalLength() override
Definition: juce_WebInputStream.cpp:46
juce::WebInputStream::connect
bool connect(Listener *listener)
Definition: juce_WebInputStream.cpp:51
juce::WebInputStream::getRequestHeaders
StringPairArray getRequestHeaders() const
Definition: juce_WebInputStream.cpp:40
juce::WebInputStream::withCustomRequestCommand
WebInputStream & withCustomRequestCommand(const String &customRequestCommand)
Definition: juce_WebInputStream.cpp:37
juce::WebInputStream::read
int read(void *destBuffer, int maxBytesToRead) override
Definition: juce_WebInputStream.cpp:47
juce::WebInputStream::WebInputStream
WebInputStream(const URL &url, const bool usePost)
Definition: juce_WebInputStream.cpp:26
juce::WebInputStream::isError
bool isError() const
Definition: juce_WebInputStream.cpp:42
juce::WebInputStream::cancel
void cancel()
Definition: juce_WebInputStream.cpp:43
juce::WebInputStream::getResponseHeaders
StringPairArray getResponseHeaders()
Definition: juce_WebInputStream.cpp:41
juce::WebInputStream::getPosition
int64 getPosition() override
Definition: juce_WebInputStream.cpp:45