Skip to content

Commit

Permalink
Fix for digest auth, update home page with new info on curl import, h…
Browse files Browse the repository at this point in the history
…ot-reloading
  • Loading branch information
darrenburns committed Nov 11, 2024
1 parent 53efd3e commit a3767f4
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 10 deletions.
2 changes: 1 addition & 1 deletion docs/guide/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ The table below lists all available configuration options and their environment

| Config Key (Env Var) | Values (Default) | Description |
|----------------------|------------------|-------------|
| `theme` (`POSTING_THEME`) | `"posting"`, `"galaxy"`, `"monokai"`, `"solarized-light"`, `"nautilus"`, `"nebula"`, `"alpine"`, `"cobalt"`, `"twilight"`, `"hacker"` (Default: `"posting"`) | Sets the theme of the application. |
| `theme` (`POSTING_THEME`) | `"posting"`, `"galaxy"`, `"monokai"`, `"solarized-light"`, `"nautilus"`, `"nebula"`, `"alpine"`, `"cobalt"`, `"twilight"`, `"hacker"` (Default: `"galaxy"`) | Sets the theme of the application. |
| `load_user_themes` (`POSTING_LOAD_USER_THEMES`) | `true`, `false` (Default: `true`) | If enabled, load user themes from the theme directory, allowing them to be specified in config and selected via the command palette. |
| `load_builtin_themes` (`POSTING_LOAD_BUILTIN_THEMES`) | `true`, `false` (Default: `true`) | If enabled, load builtin themes, allowing them to be specified in config and selected via the command palette. |
| `theme_directory` (`POSTING_THEME_DIRECTORY`) | (Default: `${XDG_DATA_HOME}/posting/themes`) | The directory containing user themes. |
Expand Down
11 changes: 8 additions & 3 deletions docs/overrides/home.html
Original file line number Diff line number Diff line change
Expand Up @@ -1665,10 +1665,12 @@ <h2 id="feature-title-1" class="feature-title">
</p>

<p class="feature-description">
Want to edit a request body in <span data-text="nvim" class="gradient-text subtle-purple-glow monospace">nvim</span> or browse a JSON response in <span data-text="fx" class="gradient-text subtle-purple-glow monospace">fx</span>? No problem!
Posting lets you use the tools you love.
Edit a request body in <span data-text="nvim" class="gradient-text subtle-purple-glow monospace">nvim</span> or browse a JSON response in <span data-text="fx" class="gradient-text subtle-purple-glow monospace">fx</span>? No problem!
</p>

<p class="feature-description">
Import <span data-text="curl" class="gradient-text subtle-purple-glow monospace">curl</span> requests into Posting by simply pasting into the URL bar.
</p>

<!-- move the version control text to a different section -->
<!-- <p class="feature-description">
After saving a request, check it into <span data-text="version control" class="gradient-text subtle-purple-glow">version control</span> - requests live on your file system, in diffable and easy to read YAML files.
Expand All @@ -1688,6 +1690,9 @@ <h2 class="feature-title">Environments</h2>
<p class="feature-description">
Load variables from one or more <span data-text="dotenv" class="gradient-text subtle-purple-glow">dotenv</span> environment files, or allow access to <span data-text="environment variables" class="gradient-text subtle-purple-glow">environment variables</span>.
</p>
<p class="feature-description">
Edit variables in your favorite editor, and Posting will <span data-text="hot reload" class="gradient-text subtle-purple-glow">hot reload</span> them.
</p>
</div>
<div class="feature-image">
<video src="assets/environments.mp4" alt="Environments in action in the URL bar" autoplay loop muted playsinline></video>
Expand Down
6 changes: 3 additions & 3 deletions src/posting/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -699,16 +699,16 @@ def on_curl_message(self, event: CurlMessage):
request_model = curl_import.to_request_model()
except Exception as e:
self.notify(
title="Could not parse curl request",
message=f"An error occurred: {e}",
title="Import error",
message=f"Couldn't import curl command.",
timeout=5,
severity="error",
)
else:
self.load_request_model(request_model)
self.notify(
title="Curl request imported",
message=f"Successfully imported curl request to {curl_import.url}",
message=f"Successfully imported request to {curl_import.url}",
timeout=3,
)

Expand Down
15 changes: 12 additions & 3 deletions src/posting/importing/curl.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,14 @@ def __init__(self, curl_command: str):
)
parser.add_argument("-e", "--referer", help="Referrer URL")
parser.add_argument("-A", "--user-agent", help="User-Agent to send to server")
parser.add_argument(
"--digest",
action="store_true",
help="Use HTTP Digest Authentication",
)
parser.add_argument("url", nargs="?")

args = parser.parse_intermixed_args(tokens)
args, extras = parser.parse_known_intermixed_args(tokens)
# Extract components
self.method = cast(
HttpRequestMethod,
Expand All @@ -92,6 +97,7 @@ def __init__(self, curl_command: str):
self.insecure = args.insecure
self.referer = args.referer
self.user_agent = args.user_agent
self.use_digest = args.digest

# Determine if the data is form data
self.is_form_data = False
Expand Down Expand Up @@ -163,8 +169,11 @@ def _extract_auth_from_headers(self) -> tuple[Auth | None, list[tuple[str, str]]
# First check the -u/--user parameter
if self.user:
username, _, password = self.user.partition(":")
# Default to empty password if none provided
auth = Auth.basic_auth(username, password)
# Use digest auth if --digest flag was provided, otherwise use basic auth
if self.use_digest:
auth = Auth.digest_auth(username, password)
else:
auth = Auth.basic_auth(username, password)

# Look for auth headers that might override the -u parameter
for name, value in self.headers:
Expand Down

0 comments on commit a3767f4

Please sign in to comment.