Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(network): remove header on insecure requests #304

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/API/Status/PreviewCard.vala
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ public class Tuba.API.PreviewCard : Entity, Widgetizable {


new Request.GET (special_api_url)
.is_insecure ()
.then ((sess, msg, in_stream) => {
bool failed = true;
var parser = Network.get_parser_from_inputstream(in_stream);
Expand Down
10 changes: 8 additions & 2 deletions src/Services/Network/Request.vala
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public class Tuba.Request : GLib.Object {
HashMap<string, string>? pars;
Soup.Multipart? form_data;
public GLib.Cancellable cancellable;
public bool insecure { get; set; default=false; }

weak Gtk.Widget? ctx;
bool has_ctx = false;
Expand Down Expand Up @@ -108,6 +109,11 @@ public class Tuba.Request : GLib.Object {
return this;
}

public Request is_insecure () {
this.insecure = true;
return this;
}

public Request with_param (string name, string val) {
if (pars == null)
pars = new HashMap<string, string> ();
Expand Down Expand Up @@ -165,8 +171,8 @@ public class Tuba.Request : GLib.Object {
msg.uri = t_uri;
}

if (account != null && account.access_token != null) {
msg.request_headers.remove ("Authorization");
msg.request_headers.remove ("Authorization");
if (account != null && account.access_token != null && !insecure) {
msg.request_headers.append ("Authorization", @"Bearer $(account.access_token)");
}

Expand Down
1 change: 1 addition & 0 deletions src/Widgets/BookWyrmPage.vala
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ public class Tuba.Widgets.BookWyrmPage : Gtk.Box {

foreach (var author in t_obj.authors) {
new Request.GET (@"$author.json")
.is_insecure ()
.then ((sess, msg, in_stream) => {
var parser = Network.get_parser_from_inputstream(in_stream);
var node = network.parse_node (parser);
Expand Down