Skip to content

Conversation

@kaustuvpokharel
Copy link
Collaborator

@kaustuvpokharel kaustuvpokharel commented Dec 18, 2025

Description
This PR introduces QFieldXmlHttpRequest, a lightweight HTTP request wrapper designed for QML usage (internal QML + plugins).
It follows an XMLHttpRequest-like workflow:
open(), setRequestHeader(), send(), abort(), readyState, response fields, and event-style callback properties.

Usage is via the QField plugin interface (iface), i.e. requests are created with:
iface.createHttpRequest()

Credits or Origin
Core idea and API inspiration taken from:
https://github.com/alirezah95/QmlHttpRequest
(Thank you! This PR re-implements/adapts the concept to match QField’s networking stack and safety constraints.)

  1. New C++ class QFieldXmlHttpRequest:
  • Supports GET, POST, PUT, DELETE
  • Uses QgsNetworkAccessManager / QNetworkReply so behavior matches the app (SSL/proxy/auth, redirects, etc.)
    -Deterministic body encoding: QByteArray sent as-is QString UTF-8 text, QVariantMap / QVariantList JSON
  • If Content-Type isn’t set, it is inferred from payload type
  • Automatically used when a map body contains file://... values
  • Can be forced with Content-Type: multipart/form-data (requires a map body)
  • Clears preset multipart Content-Type so Qt generates the correct boundary
  • Only allows files inside the current project directory or QFieldCloud local directory
  • Response headers exposed (getResponseHeader(), getAllResponseHeaders())
  • JSON responses parsed into QVariantMap / QVariantList when Content-Type indicates JSON
  • Timeout handling guards against stale timers affecting newer requests
  • Request objects are short-lived and deleteLater() automatically after completion (success/error/abort/timeout)
  1. A prototype “XHR Tester” QML plugin created to validate behavior manually:

@qfield-fairy
Copy link
Collaborator

qfield-fairy commented Dec 18, 2025

🍎 MacOS DMG universal builds

Download a MacOS DMG universal build of this PR for testing.
(Built from commit f3da727)

🐧 Linux AppImage builds

Download a Linux AppImage build of this PR for testing.
(Built from commit f3da727)

🪟 Windows builds

Download a Windows build of this PR for testing.
(Built from commit f3da727)

@qfield-fairy
Copy link
Collaborator

qfield-fairy commented Dec 18, 2025

Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clang-tidy made some suggestions

@kaustuvpokharel kaustuvpokharel marked this pull request as draft December 18, 2025 07:47
@kaustuvpokharel kaustuvpokharel marked this pull request as ready for review December 24, 2025 05:38
smaller suggested fixes

smaller suggested fixes

smaller suggested fixes
@kaustuvpokharel kaustuvpokharel force-pushed the feature/pluginWithxmlHttpRequest branch from 47ef0ae to 264c47c Compare December 24, 2025 05:54
Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clang-tidy made some suggestions

Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clang-tidy made some suggestions

@kaustuvpokharel kaustuvpokharel force-pushed the feature/pluginWithxmlHttpRequest branch from 01e81d6 to 135af48 Compare December 31, 2025 05:09
@kaustuvpokharel kaustuvpokharel force-pushed the feature/pluginWithxmlHttpRequest branch from 135af48 to e85ee21 Compare December 31, 2025 05:12
Copy link
Collaborator

@mohsenD98 mohsenD98 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work on this PR! The implementation is solid and the XMLHttpRequest-like API will be very intuitive for plugin developers 👍 Just left a minor suggestion.

@kaustuvpokharel kaustuvpokharel force-pushed the feature/pluginWithxmlHttpRequest branch from f01ae34 to f3da727 Compare January 6, 2026 22:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants