Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/dev' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
tmenier committed Jan 22, 2022
2 parents 0f52886 + 3a1fc0a commit d93af23
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 10 deletions.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2021 Todd Menier
Copyright (c) 2022 Todd Menier

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
8 changes: 8 additions & 0 deletions Test/Flurl.Test/UrlBuilder/UrlParsingTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -115,5 +115,13 @@ public void does_not_alter_url_passed_to_constructor() {
var url = new Url(expected);
Assert.AreEqual(expected, url.ToString());
}

[Test] // #656
public void queryparams_uses_equals() {
var url = new Url("http://www.mysite.com?param=1");
// String gets boxed, so we need to use Equals, instead of ==
var contains = url.QueryParams.Contains("param", "1");
Assert.IsTrue(contains);
}
}
}
19 changes: 19 additions & 0 deletions src/Flurl.Http/Content/CapturedMultipartContent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,25 @@ public CapturedMultipartContent(FlurlHttpSettings settings = null) : base("form-
_settings = settings ?? FlurlHttp.GlobalSettings;
}

/// <summary>
/// Initializes a new instance of the <see cref="CapturedMultipartContent"/> class.
/// </summary>
/// <param name="subtype">The subtype of the multipart content.</param>
/// <param name="settings">The FlurlHttpSettings used to serialize each content part. (Defaults to FlurlHttp.GlobalSettings.)</param>
public CapturedMultipartContent(string subtype, FlurlHttpSettings settings = null) : base(subtype) {
_settings = settings ?? FlurlHttp.GlobalSettings;
}

/// <summary>
/// Initializes a new instance of the <see cref="CapturedMultipartContent"/> class.
/// </summary>
/// <param name="subtype">The subtype of the multipart content.</param>
/// <param name="boundary">The boundary string for the multipart content.</param>
/// <param name="settings">The FlurlHttpSettings used to serialize each content part. (Defaults to FlurlHttp.GlobalSettings.)</param>
public CapturedMultipartContent(string subtype, string boundary, FlurlHttpSettings settings = null) : base(subtype, boundary) {
_settings = settings ?? FlurlHttp.GlobalSettings;
}

/// <summary>
/// Add a content part to the multipart request.
/// </summary>
Expand Down
4 changes: 2 additions & 2 deletions src/Flurl.Http/FlurlRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ public FlurlHttpSettings Settings {

/// <inheritdoc />
public IFlurlClient Client {
get =>
get =>
(_client != null) ? _client :
(Url != null) ? FlurlHttp.GlobalSettings.FlurlClientFactory.Get(Url) :
null;
Expand Down Expand Up @@ -205,7 +205,7 @@ public async Task<IFlurlResponse> SendAsync(HttpMethod verb, HttpContent content

private void SyncHeaders(HttpRequestMessage request) {
// copy any client-level (default) headers to this request
foreach (var header in Client.Headers.Where(h => !this.Headers.Contains(h.Name)))
foreach (var header in Client.Headers.Where(h => !this.Headers.Contains(h.Name)).ToList())
this.Headers.Add(header.Name, header.Value);

// copy headers from FlurlRequest to HttpRequestMessage
Expand Down
12 changes: 5 additions & 7 deletions src/Flurl/QueryParamCollection.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
Expand Down Expand Up @@ -56,7 +55,7 @@ public void Add(string name, object value, bool isEncoded = false, NullValueHand
return;
}

foreach (var val in SplitCollection(value)) {
foreach (var val in SplitCollection(value).ToList()) {
if (val == null && nullValueHandling != NullValueHandling.NameOnly)
continue;
_values.Add(name, new QueryParamValue(val, isEncoded));
Expand All @@ -81,7 +80,6 @@ public void AddOrReplace(string name, object value, bool isEncoded = false, Null
// example: x has values at positions 2 and 4 in the query string, then we set x to
// an array of 4 values. We want to replace the values at positions 2 and 4 with the
// first 2 values of the new array, then append the remaining 2 values to the end.
//var parameters = this.Where(p => p.Name == name).ToArray();
var values = new Queue<object>(SplitCollection(value));

var old = _values.ToArray();
Expand All @@ -93,7 +91,7 @@ public void AddOrReplace(string name, object value, bool isEncoded = false, Null
continue;
}

if (!values.Any())
if (values.Count == 0)
continue; // remove, effectively

var val = values.Dequeue();
Expand All @@ -106,7 +104,7 @@ public void AddOrReplace(string name, object value, bool isEncoded = false, Null
}

// add the rest to the end
while (values.Any()) {
while (values.Count > 0) {
Add(name, values.Dequeue(), isEncoded, nullValueHandling);
}
}
Expand All @@ -117,7 +115,7 @@ private IEnumerable<object> SplitCollection(object value) {
else if (value is string s)
yield return s;
else if (value is IEnumerable en) {
foreach (var item in en.Cast<object>().SelectMany(SplitCollection))
foreach (var item in en.Cast<object>().SelectMany(SplitCollection).ToList())
yield return item;
}
else
Expand Down Expand Up @@ -163,7 +161,7 @@ public bool TryGetFirst(string name, out object value) {
public bool Contains(string name) => _values.Contains(name);

/// <inheritdoc />>
public bool Contains(string name, object value) => _values.Any(qv => qv.Name == name && qv.Value.Value == value);
public bool Contains(string name, object value) => _values.Any(qv => qv.Name == name && qv.Value.Value.Equals(value));
}

/// <summary>
Expand Down

0 comments on commit d93af23

Please sign in to comment.