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

Draft: URL migration #30714

Draft
wants to merge 16 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
977038a
empty commit
jennifer-shehane Aug 7, 2024
2f54717
Merge branch 'develop' of https://github.com/cypress-io/cypress into …
jennifer-shehane Aug 12, 2024
085a50f
Merge branch 'develop' of https://github.com/cypress-io/cypress into …
jennifer-shehane Aug 14, 2024
d4e0c60
Merge branch 'develop' of https://github.com/cypress-io/cypress into …
jennifer-shehane Aug 14, 2024
98eb623
Merge branch 'develop' of https://github.com/cypress-io/cypress into …
jennifer-shehane Aug 16, 2024
22ecaba
Merge branch 'develop' of https://github.com/cypress-io/cypress into …
jennifer-shehane Aug 19, 2024
087a9a1
Merge branch 'develop' of https://github.com/cypress-io/cypress into …
jennifer-shehane Aug 20, 2024
7a4a26c
Merge branch 'develop' of https://github.com/cypress-io/cypress into …
jennifer-shehane Aug 22, 2024
8fcf371
Merge branch 'develop' of https://github.com/cypress-io/cypress into …
jennifer-shehane Aug 22, 2024
8ade420
Merge branch 'develop' of https://github.com/cypress-io/cypress into …
jennifer-shehane Aug 23, 2024
7905eb5
Merge branch 'develop' of https://github.com/cypress-io/cypress into …
jennifer-shehane Aug 26, 2024
df843b4
Merge branch 'develop' of https://github.com/cypress-io/cypress into …
jennifer-shehane Aug 26, 2024
d94fad3
Merge branch 'develop' of https://github.com/cypress-io/cypress into …
jennifer-shehane Aug 29, 2024
b2760ae
Merge branch 'develop' of https://github.com/cypress-io/cypress into …
jennifer-shehane Aug 30, 2024
33168fb
Merge branch 'develop' of https://github.com/cypress-io/cypress into …
jennifer-shehane Sep 4, 2024
df2d4c0
commit initial changes
jennifer-shehane Sep 9, 2024
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
8 changes: 5 additions & 3 deletions packages/server/lib/file_server.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

const _ = require('lodash')
const debug = require('debug')('cypress:server:file_server')
const url = require('url')
const http = require('http')
const path = require('path')
const send = require('send')
Expand All @@ -27,16 +26,19 @@ const onRequest = function (req, res, expectedToken, fileServerFolder) {
req.url,
])

const fileServerUrl = new URL(path.join(...args))
const reqUrl = new URL(req.url)

// strip off any query params from our req's url
// since we're pulling this from the file system
// it does not understand query params
// and make sure we decode the uri which swaps out
// %20 with white space
const file = decodeURI(url.parse(path.join(...args)).pathname)
const file = decodeURI(fileServerUrl.pathname)

res.setHeader('x-cypress-file-path', encodeURI(file))

return send(req, url.parse(req.url).pathname, {
return send(req, reqUrl.pathname, {
root: path.resolve(fileServerFolder),
})
.on('error', (err) => {
Expand Down
2 changes: 1 addition & 1 deletion packages/server/lib/request.js
Original file line number Diff line number Diff line change
Expand Up @@ -551,7 +551,7 @@ module.exports = function (options = {}) {
cookies = [cookies]
}

const parsedUrl = url.parse(resUrl)
const parsedUrl = new URL(resUrl)
const defaultDomain = parsedUrl.hostname

debug('setting cookies on browser %o', { url: parsedUrl.href, defaultDomain, cookies })
Expand Down
6 changes: 3 additions & 3 deletions packages/server/lib/server-base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -605,7 +605,7 @@ export class ServerBase<TSocket extends SocketE2E | SocketCt> {
// get the protocol using req.connection.encrypted
// get the port & hostname from host header
const fullUrl = `${req.connection.encrypted ? 'https' : 'http'}://${host}`
const { hostname, protocol } = url.parse(fullUrl)
const { hostname, protocol } = new URL(fullUrl)
const { port } = cors.parseUrlIntoHostProtocolDomainTldPort(fullUrl)

const onProxyErr = (err, req, res) => {
Expand Down Expand Up @@ -766,9 +766,9 @@ export class ServerBase<TSocket extends SocketE2E | SocketCt> {
// nuke any hashes from our url since
// those those are client only and do
// not apply to http requests
urlStr = url.parse(urlStr)
urlStr = new URL(urlStr)
urlStr.hash = null
urlStr = urlStr.format()
urlStr = urlStr.href

const originalUrl = urlStr

Expand Down
5 changes: 2 additions & 3 deletions packages/server/lib/util/ensure-url.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import _ from 'lodash'
import Bluebird from 'bluebird'
import debugModule from 'debug'
import rp from '@cypress/request-promise'
import * as url from 'url'
import { agent, connect } from '@packages/network'

const debug = debugModule('cypress:server:ensure-url')
Expand Down Expand Up @@ -50,9 +49,9 @@ export const retryIsListening = (urlStr: string, options: RetryOptions) => {

export const isListening = (urlStr: string) => {
// takes a urlStr and verifies the hostname + port is listening
let { hostname, protocol, port } = url.parse(urlStr)
let { hostname, protocol, port } = new URL(urlStr)

if (port == null) {
if (port.length === 0) {
port = protocol === 'https:' ? '443' : '80'
}

Expand Down
7 changes: 3 additions & 4 deletions packages/server/test/integration/http_requests_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ const compression = require('compression')
const dns = require('dns')
const express = require('express')
const http = require('http')
const url = require('url')
let zlib = require('zlib')
const str = require('underscore.string')
const evilDns = require('evil-dns')
Expand Down Expand Up @@ -4416,15 +4415,15 @@ describe('Routes', () => {
Fixtures.scaffoldProject('e2e')
.then(() => {
this.httpSrv = http.createServer((req, res) => {
const { query } = url.parse(req.url, true)
const { search } = new URL(req.url, true)

if (_.has(query, 'chunked')) {
if (_.has(search, 'chunked')) {
res.setHeader('tranfer-encoding', 'chunked')
} else {
res.setHeader('content-length', '0')
}

res.writeHead(Number(query.status), {
res.writeHead(Number(search.status), {
'x-foo': 'bar',
})

Expand Down
2 changes: 1 addition & 1 deletion packages/server/test/unit/fixture_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ describe('lib/fixture', () => {
})

context('file not found', () => {
it('throws when file cannot be found', function () {
it('throws when file cannot be found', async function () {
const p = 'does-not-exist.json'

return fixture.get(this.fixturesFolder, p)
Expand Down
Loading