Files
Jungfraujoch/viewer/JFJochHttpReader.h
T
leonarski_fandClaude Opus 4.8 49d078563c viewer: move JFJochHttpReader to the viewer and switch it to libcurl
JFJochHttpReader (the viewer's live-broker HTTP client) is the only HTTP client
in the reader library and the only piece that needs TLS + Kerberos. Moving it out
of the always-built JFJochReader keeps the broker/writer free of a TLS/Kerberos
stack; switching it from cpp-httplib to libcurl gives the viewer HTTPS and, later,
GSSAPI/Bearer auth.

- Move reader/JFJochHttpReader.{cpp,h} -> viewer/, compiled into jfjoch_viewer.
- Rewrite the 10 httplib call sites onto one libcurl easy-handle Request() helper
  (GET + PUT, binary/JSON bodies; status/transport handling preserved).
- CMake: FetchContent libcurl, STATIC, HTTP(S)-only, only for viewer builds.
  OS-native backends keep Windows self-contained (Schannel+SSPI); Linux uses
  system OpenSSL + GSSAPI (krb5). Drop httplib from JFJochReader.
- Block httplib OpenSSL auto-link (HTTPLIB_USE_OPENSSL_IF_AVAILABLE OFF) so the
  broker stops pulling in libssl/libcrypto for HTTPS it never serves.
- docker: add krb5 dev headers (libkrb5-dev / krb5-devel) for CURL_USE_GSSAPI.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-11 15:19:58 +02:00

68 lines
2.7 KiB
C++

// SPDX-FileCopyrightText: 2025 Filip Leonarski, Paul Scherrer Institute <filip.leonarski@psi.ch>
// SPDX-License-Identifier: GPL-3.0-only
#pragma once
#include "../reader/JFJochReader.h"
#include "../common/BrokerStatus.h"
#include "../common/ImageBuffer.h"
#include "../common/ROIDefinition.h"
class JFJochHttpReader : public JFJochReader {
mutable std::mutex http_mutex;
std::string addr;
std::optional<int64_t> last_image_buffer_counter;
bool last_op_http_sync = false;
// Cache of the (constant-per-acquisition) pixel mask, keyed on arm date, so the per-refresh
// dataset rebuild reuses one shared mask instead of reconstructing it every tick.
std::shared_ptr<const PixelMask> cached_pixel_mask;
std::string cached_pixel_mask_arm_date;
// Minimal HTTP result: whether a response arrived (transport-level success), the HTTP status
// code, and the (possibly binary) response body.
struct HttpResult {
bool ok = false;
long status = 0;
std::string body;
};
// Single libcurl request helper behind every endpoint call. method is "GET" or "PUT"; for PUT
// the body is sent with the given content_type.
HttpResult Request(const std::string &method, const std::string &path,
const std::string &body = {}, const std::string &content_type = {}) const;
ImageBufferStatus GetImageBufferStatus() const;
bool LoadImage_i(std::shared_ptr<JFJochReaderDataset> &dataset,
DataMessage& message,
std::vector<uint8_t> &buffer,
int64_t image_number,
bool update_dataset) override;
std::shared_ptr<JFJochReaderDataset> UpdateDataset_i();
std::vector<float> GetPlot_i(const std::string &plot_type, float fill_value = 0.0) const;
public:
~JFJochHttpReader() override = default;
void ReadURL(const std::string& url);
uint64_t GetNumberOfImages() const override;
void Close() override;
// Refresh dataset/plots if the image buffer changed since the last poll (returns nullptr if
// unchanged). Always writes the current number of images to num_images_out. Does not load an image.
std::shared_ptr<const JFJochReaderDataset> RefreshDatasetIfChanged(int64_t &num_images_out);
void UploadUserMask(const std::vector<uint32_t>& mask);
[[nodiscard]] ROIDefinition GetROIDefinitions() const; // GET /config/roi
void UploadROIDefinitions(const ROIDefinition &rois) const; // PUT /config/roi
BrokerStatus GetBrokerStatus() const;
std::shared_ptr<JFJochReaderRawImage> GetRawImage(int64_t image_number) override;
std::vector<SpotToSave> ReadSpots(int64_t image) const override;
};