From 2d37a4309df60a32adba1e4d95412cadf05d62b5 Mon Sep 17 00:00:00 2001 From: amystamile-usgs Date: Fri, 20 Dec 2024 12:19:31 -0700 Subject: [PATCH] Updates SpiceClient to handle redirect requests --- CHANGELOG.md | 1 + isis/src/base/apps/spiceinit/SpiceClient.cpp | 34 +++++++------------- 2 files changed, 13 insertions(+), 22 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c3bd6caffc..7aee91fdc3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -41,6 +41,7 @@ release. ### Fixed - Fixed kaguyatc2isis invalid BandBin values [#5629](https://github.com/DOI-USGS/ISIS3/issues/5629) +- Fixed SpiceClient to handle redirect requests. ## [9.0.0] - 09-25-2024 diff --git a/isis/src/base/apps/spiceinit/SpiceClient.cpp b/isis/src/base/apps/spiceinit/SpiceClient.cpp index 84984d1d9c..3156ee7f54 100644 --- a/isis/src/base/apps/spiceinit/SpiceClient.cpp +++ b/isis/src/base/apps/spiceinit/SpiceClient.cpp @@ -85,25 +85,6 @@ namespace Isis { *p_xml = QString(QByteArray(raw.toLatin1()).toHex().constData()); - /* - * For Debugging, you may want to run spiceserver locally (without spiceinit). - * - * Uncomment the following code and run the spiceinit with web=true. An error will be thrown - * with the file name of the stored input hex file. You can rsync that file to your work area - * and run spiceserver locally. - */ - - // const char *inmode = "overwrite"; - // const char *ext = "dat"; - // TextFile newInput; - // QString serverInputFile("/tmp/input"); - // newInput.Open(serverInputFile, inmode, ext); - // newInput.Rewind();//start at begining - // newInput.PutLine(hexCode); - // newInput.Close(); - // QString msg = "Exporting expected server input to: " + serverInputFile; - // throw IException(IException::Programmer, msg, _FILEINFO_); - int contentLength = p_xml->length(); QString contentLengthStr = toString((BigInt)contentLength); @@ -112,9 +93,6 @@ namespace Isis { p_request->setRawHeader("User-Agent", "SpiceInit 1.0"); p_request->setHeader(QNetworkRequest::ContentTypeHeader, "application/x-www-form-urlencoded"); - //p_request->setRawHeader("Content-Length", contentLengthStr.c_str()); - //p_request->setAttribute(QNetworkRequest::DoNotBufferUploadDataAttribute, - // true); moveToThread(this); start(); @@ -179,6 +157,18 @@ namespace Isis { * @param reply */ void SpiceClient::replyFinished(QNetworkReply *reply) { + // Check for redirection + QVariant redirectionTarget = reply->attribute(QNetworkRequest::RedirectionTargetAttribute); + if (!redirectionTarget.isNull()) { + QUrl redirectedUrl = redirectionTarget.toUrl(); + + // Update the request with the new URL and re-send + p_request->setUrl(redirectedUrl); + sendRequest(); + return; + } + + // No redirection, proceed with the original processing p_rawResponse = new QString(QString(reply->readAll())); // Decode the response