diff --git a/mongoose.c b/mongoose.c
index a9ea7c8d4aef7b30de7fc10eb6ed86efffd96479..587422d329d1489e7ceabc1bfc12fe843a89715a 100644
--- a/mongoose.c
+++ b/mongoose.c
@@ -1750,6 +1750,18 @@ const char *mg_strstr(const struct mg_str haystack,
   }
   return NULL;
 }
+
+struct mg_str mg_strstrip(struct mg_str s) WEAK;
+struct mg_str mg_strstrip(struct mg_str s) {
+  while (s.len > 0 && isspace((int) *s.p)) {
+    s.p++;
+    s.len--;
+  }
+  while (s.len > 0 && isspace((int) *(s.p + s.len - 1))) {
+    s.len--;
+  }
+  return s;
+}
 #ifdef MG_MODULE_LINES
 #line 1 "common/str_util.c"
 #endif
diff --git a/mongoose.h b/mongoose.h
index 5eeaee66e586c541c0be7697f2690010f5e1b2f1..5f9219db5e9ef60b2169bae64a703990bb5429cb 100644
--- a/mongoose.h
+++ b/mongoose.h
@@ -2283,6 +2283,9 @@ int mg_strncmp(const struct mg_str str1, const struct mg_str str2, size_t n);
  */
 const char *mg_strstr(const struct mg_str haystack, const struct mg_str needle);
 
+/* Strip whitespace at the start and the end of s */
+struct mg_str mg_strstrip(struct mg_str s);
+
 #ifdef __cplusplus
 }
 #endif